Hello!
I have a component attached to my player (airplane):
public class PlaneEject : NetworkBehaviour {
public GameObject player; // Player prefab
void Update() {
// Eject button (B)
if (!pilotEjected && CrossPlatformInputManager.GetButtonDown ("Jump")) {
CmdEject(gameObject);
}
}
[Command]
public void CmdEject (GameObject plane) {
NetworkIdentity netIdentity = plane.GetComponent<NetworkIdentity>();
NetworkConnection conn = netIdentity.connectionToClient;
GameObject playerClone = Instantiate (player, plane.transform.position, Quaternion.identity) as GameObject;
// Not sure if i need this, doesn't make any difference:
// ClientScene.SetLocalObject(netIdentity.netId, playerClone);
NetworkServer.ReplacePlayerForConnection(conn, playerClone, 0);
}
}
If I press eject botton on the server side, a player got spawned, (ejected from the airplane) but I can’t see it on the client side.
If I press eject botton on the client side, getting different errors:
Trying to send command for object without authority.
UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
PlaneEject:CallCmdEject(GameObject)
and a bunch of warnings
Did not find target for sync message for 4
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
Can’t figure out what am I doing wrong here. Unity documentation code on Switching Players has pretty much the same code I have.
