- Home /
How to get players to re-spawn with a RPC.
Greetings everyone, I'm just trying to figure out how to do networking in Unity. I found a nice tutorial, and now I'm trying to get an function to run on every client connected so that I have one button to spawn all of the players by using Network.player.ToString() to a specified location.
This is my Update function:
void Update()
{
if (networkView.isMine)
{
InputMovement();
InputColorChange();
if (Input.GetKeyDown(KeyCode.R)){
networkView.RPC ("adminPower", RPCMode.All);
}
}
else
{
SyncedMovement();
}
}
And this is my adminPower-function:
[RPC]
private void adminPower(){
//networkView.RPC("adminPower", RPCMode.AllBuffered);
print ("hi");
if (Network.player.ToString() == "0"){
Debug.Log(Network.player.ToString());
myRigid.MovePosition (new Vector3(4,1,0));
}
if (Network.player.ToString() == "1"){
Debug.Log(Network.player.ToString());
myRigid.MovePosition (new Vector3(0,1,2));
}
if (Network.player.ToString() == "2"){
myRigid.transform.position = new Vector3(4,1,0);
Debug.Log(Network.player.ToString());
}
if (Network.player.ToString() == "3"){
myRigid.transform.position = new Vector3(0,1,4);
Debug.Log(Network.player.ToString());
}
}
So the adminPower-function kinda works, the client I'm pressing R on is moved to the location specified by the if (Network.player.ToString() == "X"). The problem is that all of the other players connected wont be moved anywhere and I have no idea why since I thought that the RPC-tag would make the function be called on every client?
Link to the whole project is here: https://dl.dropboxusercontent.com/u/1148172/MultiplayerTutorial.zip
Thank you for time.
I'm working with something similar and are having the same issues. Help would be much appreciated.
Please describe the problem a bit more. I tested your link in 4 Unity instances (1 server + 3 clients) and I see the clones of the player are moving properly on all when player is moving.
Your answer
Follow this Question
Related Questions
Is this the right setup for a multiplayer game? 0 Answers
playerControllerId higher than expected 1 Answer
Network.Spawned objects won't show on new client 1 Answer
Network spawning 1 Answer
Network client : cannot fire 0 Answers