- Home /
Question by
Sruthin55 · Apr 30, 2016 at 11:40 AM ·
networkingsynchronization
Synvar hook firing but value not getting updated on client
I have this weird problem where the syncvar hook function is called on the client , getting the new values but when I call the variable in update it is still having the old value like it never got the new value
[SyncVar (hook = "OnPlayer2TransformXChange")]
public float Player2TransfromX = 0.0f;
[SyncVar (hook = "OnPlayer2TransformYChange")]
public float Player2TransfromY =0.0f;
[SyncVar (hook = "OnPlayer2TransformZChange")]
public float Player2TransfromZ = 0.0f;
[SyncVar (hook = "OnPlayer2PositionChange")]
public virtual void OnPlayer2PositionChange (bool newVal ){
Debug.Log ("OnPlayer2PositionChange---------------------------");
isPlayer2positionSet = newVal;
Debug.Log (isPlayer2positionSet);
player2Bool = true;
}
public virtual void OnPlayer2TransformXChange (float Val ){
Debug.Log ("OnPlayer2TransformChangeX---------------------------");
Debug.Log (Val);
Player2TransfromX = Val;
}
[
public virtual void OnPlayer2TransformYChange (float Val ){
Debug.Log ("OnPlayer2TransformChangeY---------------------------");
Debug.Log (Val);
Player2TransfromY = Val;
}
[
public virtual void OnPlayer2TransformZChange (float Val ){
Debug.Log ("OnPlayer2TransformChangeZ---------------------------");
Debug.Log (Val);
Player2TransfromZ = Val;
}
[Command]
public void CmdStartRace() {
if (isServer) {
int noOfSpawnPoints = spawnPointsList.Count;
for (int i = 1; i <= noOfSpawnPoints; i++) {
int randNumber = Random.Range (0, spawnPointsList.Count);
string PlayerPosition = "Player" + i.ToString ();
GameObject PlayerPositionObject = GameObject.FindGameObjectWithTag (PlayerPosition);
if(PlayerPosition == "Player2"){
// PlayerPositionObject.GetComponent<NetworkIdentity> ().RemoveClientAuthority (connectionToClient);
// PlayerPositionObject.GetComponent<NetworkTransform>(). transform.position = spawnPointsList [randNumber].transform.position;
// PlayerPositionObject.GetComponent<NetworkIdentity> ().AssignClientAuthority (connectionToClient );
Player2TransfromX = spawnPointsList [randNumber].transform.position.x;
Player2TransfromY = spawnPointsList [randNumber].transform.position.y;
Player2TransfromZ = spawnPointsList [randNumber].transform.position.z;
isPlayer2positionSet = true;
SetDirtyBit(1u);
}
PlayerPositionObject.transform.position = spawnPointsList [randNumber].transform.position;
spawnPointsList.Remove(spawnPointsList [randNumber]);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Spawing Hololens Camera OR ARCamera at user defined spawn locations 0 Answers
Synchronizing Item Crates 0 Answers
Why is my SyncVar int not resynchronizing every time a client connects? 0 Answers
Synchronizing game object across clients 2 Answers
SyncEvent bug: "Cannot cast from source type to destination type" 1 Answer