Script not working on Colliders
I am trying to make a flappy bird sort of game and have come across two problems.
First the piece of code below does not work:
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "ScoreZone") { //register a score event OnPlayerScored(); //event sent to GameManager; //play a sound } if (col.gameObject.tag == "DeadZone") { rigidBody.simulated = false; OnPlayerDied(); } }
}
Regarding the Unity settings, both my Pipes and Ground have an active Box Collider and it has the "Is Trigger" setting on. Also the Bird has a "Rigid Body" that has the Is "Simulated" option On and a Circle Collider with the Is Trigger option On. I did everything according to the instructions, but when I added the TapController script to the bird it only worked with the values that are regarding the actual movement of the Bird. I have marked my Ground and Pipes as DeadZone as marked in the code, but for some reason it does not recognize this particular part of the script: } if (col.gameObject.tag == "DeadZone") { rigidBody.simulated = false; OnPlayerDied(); } }
One other thing I noticed is that I also have a "ScoreZone" tag and when my bird passes through that it works fine, just not with the DeadZone, where it just passes through, despite the code instructions. No errors appear when I save the code, so it should work, but it doesn't. The bird flaps up and down as it should, but does not collide with the DeadZone on neither the Pipes or Ground and therefore cannot trigger the other events such as the Replay menu etc.
I would be very grateful for any advise and will attach the full code written so far.
Thank you very much for your assistance.link text
Your answer
![](https://koobas.hobune.stream/wayback/20220613011905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to call OnTrigerCollider2D() without binding any script to the Collider2D directly? 1 Answer
OnTriggerEnter2D problem 1 Answer
Script to random set active a child object? 0 Answers
2d Sprite creation at 0,0,0 with camera at 0,0,0 but renders wayyy off screen 0 Answers
How to make a random object generator that responds to simple touch? 0 Answers