Got my ship to respawn

So I went off on my own a bit and, using some of what I learned from the previous course, I managed to get my ship to die and respawn when it hits an obstacle. Feeling pretty pleased with myself so I wanted to show it here. :smiley:

Here’s the code:

  void OnCollisionEnter(Collision collision)
    {
        switch (collision.gameObject.tag)
        {
            case "Safe":
                print("We're safe!");
                break;

            default:
                print("We're dead!");
                gameObject.SetActive(false);
                Invoke("Respawn", 2f);
                break;
        }

}
   private void Respawn()
    {
        gameObject.transform.position = new Vector3(0, 2, 0);
        gameObject.transform.rotation = Quaternion.identity;
        gameObject.SetActive(true);
    }
3 Likes

Privacy & Terms