Hey all,
I’m working on a game in which players have to push other players of a platform using their vehicle. Got to most of the basics of this already setup. The problem which I’m facing is some really weird behaviour when trying to respawn players after they hit an respawn trigger under the map. Getting error of the player not having authority over the respawned object and the game basicly just crashes because the player is stuck into the trigger.
public class Client_Vehicle_Respawn : NetworkBehaviour
{
public bool TouchedTrigger = false;
private NetworkManager_Custom Net_Custom;
void Start()
{
Net_Custom = GameObject.Find ("NetworkManager").GetComponent<NetworkManager_Custom> ();
}
// Update is called once per frame
void Update ()
{
RespawnPlayer ();
}
[ClientCallback]
public void RespawnPlayer()
{
if(TouchedTrigger == true)
{
Debug.Log("Touched Trigger");
CmdRespawnSvr();
TouchedTrigger = false;
}
}
[Command]
void CmdRespawnSvr(){
Transform spawn = NetworkManager.singleton.GetStartPosition();
GameObject newPlayer = Instantiate(NetworkManager.singleton.playerPrefab, spawn.position, spawn.rotation ) as GameObject;
GameObject.Find("Main Camera").SetActive(true);
NetworkServer.Destroy( this.gameObject );
NetworkServer.ReplacePlayerForConnection( this.connectionToClient, newPlayer, this.playerControllerId );
Debug.Log("I am destroyed");
}
}
I hope anyone knows how to solve this weird kinda problem.
-Speedex