using UnityEngine;
using System.Collections;
using TNet;
public class GamePlayer : TNBehaviour {
static public GamePlayer istance;
public float speed = 80.0F;
public float gravity = 20.0F;
// Movimenti
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
private Vector3 movimento
= new Vector3
(0,
0,
0);
//
void Awake()
{
istance = this;
controller = GetComponent<CharacterController>();
}
void Start()
{
//
if(!tno.isMine)
{
Camera[] allChildren = GetComponentsInChildren<Camera>();
foreach (Camera child in allChildren) {
child.enabled = false;
}
}
}
//
void Update()
{
if(tno.isMine)
{
Movimenti();
}
// Movimento
if(Mathf.Abs(movimento.x) > 0.8 || Mathf.Abs(movimento.z) > 0.8)
{
controller.Move(movimento * Time.deltaTime);
}
}
void Movimenti() {
moveDirection
= new Vector3
(0,
0,
0); float input_v = Input.GetAxis("Vertical");
//
if(input_v != 0)
{
// Muovo avanti/indietro in base all'input
moveDirection
= new Vector3
(0,
0, input_v
); moveDirection = transform.TransformDirection(moveDirection);
// Velocità di movimento
moveDirection *= speed;
}
// Making the character move
if(moveDirection != Vector3.zero)
{
// Gravity
moveDirection.y -= gravity;
tno.Send("OnSetDestinazioneMovimento", TNet.Target.Others, moveDirection);
OnSetDestinazioneMovimento(moveDirection);
}
}
[RFC]
void OnSetDestinazioneMovimento(Vector3 destinazione)
{
movimento = destinazione;
}
}