Hi, I have a critical problem using UNET technology. I have a TestShip prefab (the player object) with some
components as in the picture below:
these are the scripts used for this test case:
The first one is the PlayerController used to manage player movements
public class PlayerController : NetworkBehaviour {
[SerializeField]
float Speed = 2f;
void Start () {
}
void Update () {
if (isLocalPlayer)
{
ClientInputUpdate();
CameraUpdate();
}
}
void ClientInputUpdate()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
GetComponent<Rigidbody2D>().velocity = new Vector2(h * Speed, v * Speed);
}
void CameraUpdate()
{
Vector3 pos = transform.position;
pos.z = Camera.main.transform.position.z;
Camera.main.transform.position = pos;
}
}
And the “Other” Script, used to learn how SyncVars work
public class Other : NetworkBehaviour {
[SyncVar]
public int Foo = 1234;
void Start () {
}
void Update () {
}
}
When i debug scene an error occurs:
When I move my ship around the scene, on the client I see that my SyncVar “Foo” changes as each ship position’s change. Why? What is wrong?