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

Respawn code not working

Discussion in 'Scripting' started by Beef331, Jun 5, 2014.

  1. Beef331

    Beef331

    Joined:
    Jul 19, 2013
    Posts:
    15
    var respawn = Vector3 (0, 2, 0);

    function OnCollisionEnter (collision:Collision){
    while(UnityEngine.Collision.GameObject("Player"));{
    transform.Translate(respawn);
    }
    }



    Using this code I get the error, MissingMethodException: UnityEngine.Collision.GameObject, could you please help me fix this error.
     
  2. StaticNova

    StaticNova

    Joined:
    Feb 23, 2013
    Posts:
    60
    Instead of UnityEngine.Collision.GameObject, it should just be collision.gameObject. Also is Player the name of the gameObject? If so it should be this: collision.gameObject.name == "Player"
     
  3. Beef331

    Beef331

    Joined:
    Jul 19, 2013
    Posts:
    15
    thanks but now its crashing unity
     
    Last edited: Jun 5, 2014
  4. StaticNova

    StaticNova

    Joined:
    Feb 23, 2013
    Posts:
    60
    That means the while is causing an infinite loop. Make sure the condition can be met for it to stop.