- Home /
OnTriggerEnter is not working! I have tried absolutely everything I can think of.
I am working on a project and the goal of my script is to set the first state of a gameobject inactive and then set the second state active when colliding with a gameobject with the tag "Ball." I have made sure one or both of the trigger objects has a rigidbody and that one of them has isTrigger on and the other off. Everything I can think of does not work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpPad : MonoBehaviour
{
public GameObject State1;
public GameObject State2;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball"))
{
State1.SetActive(false);
State2.SetActive(true);
}
}
}
So I am curious just for the heck of it you could try this: if (other.gameObject.CompareTag("Ball"))
I was considering that. I will go ahead and try to see what happens.
Have you checked the manual? The matrix at the bottom of the page will show you the conditions required for the OnTriggerEnter to be called.
Also, keep in $$anonymous$$d that if you're working with 2D physics objects, you need to implement OnTriggerEnter2D.
Yep, they all are correc. The thing is, I have used the same scripts on another object, and it works. I have checked my object as many times as I can count.
Can you edit your question and provide a screenshot of the gameObjects involved in the collision?
Are you also sure OnTriggerEnter
is not called? It may be your tag comparison that fails.
use debug.log to return information about the collision .
debug.log(other.name) can you post a screenshot ?
Answer by juliann10121 · Dec 04, 2021 at 10:57 PM
I'd say double check all of your gameobjects are assigned, triple check your triggers are set correctly, and check that the script is attached to the correct object in your hierarchy. They may seem simple, but they are often things that my brain skips over.
Your answer
Follow this Question
Related Questions
How do I ignore trigger objects for collision? 0 Answers
Collision detection for low relative velocity, high world velocity rigidbodies 2 Answers
Collide crafting system 0 Answers
Troublesome collision detection when changing rigidbody.velocity directly 0 Answers
OnTrigger event when colliders are already touching eachother 1 Answer