-11

I want to know how to create a function in c# which is called when my bird gameobject touches the ground or top of the screen. I want it to call game over when this happens. I've tried comparing bird.position.x with Screen height but it didnt work, I hope you have another way to do it. Thanks

Mr.Bigglesworth
  • 924
  • 9
  • 22
  • 1
    Unity has a very complete framework which allows you to handle collision easily. You need to learn more about that framework and watch some more tutorials. – Joe Hackerberg Feb 28 '17 at 13:50

1 Answers1

1

The function you are looking for is called OnTriggerEnter2D

void OnTriggerEnter2D(Collider other) {
         if(other.gameObject.tag == "Floor")
              //You lost
 }

You need to place this function in a Scrip in the bird gameobject, then add colliders to the bird and the floor, and assign a tag to the floor so you can check inside the OnTriggerEnter2D is the bird crashed against the floor.

Ignacio Alorre
  • 7,307
  • 8
  • 57
  • 94