Search Unity

Respawn script

Discussion in 'Scripting' started by Dari, Sep 29, 2013.

  1. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    Hello, I keep trying to create multiplayer respawn script, here is the script:

    Code (csharp):
    1. function OnTriggerEnter (other : Collider) {
    2.  
    3. if (other.gameObject.tag == "Bullet") {
    4.     gameObject.transform.position = GameObject.Find("BlueSpawn").transform.position;
    5.     gameObject.transform.rotation = GameObject.Find("BlueSpawn").transform.rotation;
    6.     Destroy(other.gameObject);
    7.     }
    8. }
    I attached this script on player and when the bullet prefab trigger collides with player it says the following errors:

    NullReferenceException
    RespawnerBlue.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Cubes/RespawnerBlue.js:4)

    My bullet prefab has trigger collision and player has normal collision but it's still not working, please help me! (this is my last step for a multiplayer game so I'd like to finish it) :)
    Thanks!
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    It's basically saying it can't find "BlueSpawn" so it's returning a null. That's assuming your line numbers were copied properly.