Hi everyone,
Im trying to instantiate my player character over the network using RPCs and Network.AllocateViewID. So Im trying to have the client allocate and send RPC for local instantiations on other connections.
The problem is: The character is getting instantiated but I cannot control him, his ViewID is 0. Im kind of really lost here if anyone could help me out. I appreciate it. :)
`void OnConnectedToServer()
{if (!initialize_player) { initialize_player = true; }
}
void OnGUI()
{if (Network.isClient) { if (GUILayout.Button("SpawnPlayer")) { //Network.Instantiate(playerPrefab, player_spawn_position, transform.rotation, 0); NetworkViewID viewID = Network.AllocateViewID(); networkView.RPC("SpawnPlayer", RPCMode.AllBuffered, viewID, transform.position); } }
}
[RPC]
void SpawnPlayer(NetworkViewID viewID, Vector3 location){
GameObject clone;
clone = Instantiate(playerPrefab, location, Quaternion.identity) as GameObject;
NetworkView nView;
nView = clone.GetComponent();
nView.viewID = viewID;
}
`