- Home /
Question by
mika132132 · Dec 01, 2017 at 12:14 PM ·
unity 5gameobjectnetworkingrpcclient-server
Changing variable value Network
Hello!
I try make system where GameObject position will change if i press button "Choose". Button code works like this:
allCharacter = GameObject.FindGameObjectsWithTag("character");
if(GUI.Button(new Rect(510, yAk, 200, 30), "Choose")) {
Vector3 posWillBe = new Vector3(-2.5f+(2.4f * manysChoose), 0f, 4.37f);
if(isServer) {
allCharacter[i].GetComponent<Char>().RpcRespawn(posWillBe);
} else {
allCharacter[i].GetComponent<Char>().Cmd_MoveObject(posWillBe);
}
manysChoose++;
}
And Char.cs functions are like this:
[ClientRpc]
public void RpcRespawn(Vector3 pos)
{
Debug.Log("Change pos to " +pos);
myPosition = pos;
transform.position = myPosition;
}
[Command]
public void Cmd_MoveObject(Vector3 pos) {
if(!isClient) {
Debug.Log("We come in Cmd_MoveObject function By CLIENT");
myPosition = pos;
transform.position = myPosition;
}
myPosition = pos;
Debug.Log("We can add pos now to = " +myPosition);
RpcRespawn(pos);
}
When HOST press Choose. Character come like it should be, but when Client press "Choose" character will not change it position to anywhere. It's not come in client game and it's not come in Host game.
Comment
Answer by mika132132 · Dec 05, 2017 at 09:50 AM
Up this. If someone can help me. i still have this problem. =(