what i want simply is to get the host player position
and pass it to a text in the client side
as u see i use [SyncVar]
to get Vector3 (playerpos )
and in the server side i pass player position to that Vector3 (playerpos)
then i call vector3 value and pass it to client text
but nothing work , What is wrong here ?
I’m not sure if this is your issue, but why are you checking “if (isServer && isClient)”? Add some debug.log messages to see where your code is going.
to insure that is the Host not the client
[SyncVar(hook = "UpdatePos")]
public Vector3 playerpos;
private void Update()
{
if (isLocalPlayer && NetworkServer.active)
{
tst_text2.text = "this is server ";
playerpos = transform.position;
}
}
private void UpdatePos(Vector3 pos)
{
playerpos = pos;
tst_text2.text = "here is client";
tst_text.text = playerpos.ToString();
}
Why update function is private ?
Because Update is always private.
This:
void Update()
{
}
and this:
private void Update()
{
}
are exactly the same
1 Like