OnTriggerEnter has a weird bug, help me pls
As I said, the OnTriggerEnter function has a bug... I have a fairly simple game, where you have to complete a level and go around obstacles. Btw I'm a beginner in Unity. So, I want that that function triggers when I reach the end of the level, but that function gets triggered every time I touch the ground. Does anyone know how to solve this problem? Like I said, I'm a beginner so I have basically no idea. Thanks!
Answer by blueshark- · Feb 05, 2019 at 10:20 PM
Can you send the code? It may be that you are not looking for a tag, layer, name or other parameter.
void OnTriggerEnter(Collider other)
{
// Do something..
// Looks for any trigger enter by the object regardless of layer, tag or
// name or any other parameter.
}
If you want to look for a tag as well you could do:
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Hazard"))
{
// Do something...
// Checks for trigger enters while looking at a tag 'Hazard' on the trigger object
}
}
That looks for a tag. You could do this also by changing it to this:
private void OnTriggerEnter(Collider other, string tag)
{
if (other.gameObject.tag == "Hazard")
{
// Do something... Same behaviour as first tag option
}
}
Your answer
Follow this Question
Related Questions
localscale not working 1 Answer
Camera Jitters When Displacing and Rotating Smoothly 0 Answers
Character Controller rotation not working. 0 Answers
Screenshot on Android 2 Answers