Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

isLocalPlayer turns false after respawn

Discussion in 'Multiplayer' started by Paperfrog, Nov 13, 2015.

  1. Paperfrog

    Paperfrog

    Joined:
    Apr 9, 2014
    Posts:
    6
    Hi, I have a player object being spawned automatically by the NetworkManager and when it get spawned for the first time everything works just fine (isLocalPlayer == true). But when I later destroy the player object and it respawns, isLocalPlayer now returns false. The code I'm using to destroy and instantiate the player: (Do I perhaps need to add something? Auto Create Player is set on the NetworkManager)

    Code (csharp):
    1. //When health is out...
    2.  
    3. void PlayerDefeated () {
    4.     Destroy(gameObject);
    5.     GameObject playerClone = Instantiate(Resources.Load ("Player/Player"),new Vector3(0,0,0),Quaternion.identity) as GameObject;
    6.  }
     
  2. rchmiel

    rchmiel

    Joined:
    Apr 5, 2015
    Posts:
    49
    I thing you can not use Destroy function. Later anyway you will agan Instantiate player?! Better use gameObject.SetActive(false) to disable object.