The question is answered, right answer was accepted
How to have a game object register its OnTriggerEnter function?
I'm working on a 2D Plateformer. A mechanic in the game is that the gravity reverses when the player passes through a certain section of the level. On my player I have a script with the following function:
void OnTriggerEnter(Collider other)
{
switch (other.tag)
{
case "GravityDown":
Physics2D.gravity = new Vector2(0f, -9.81f);
Debug.Log("Gravity is Down");
break;
case "GravityUp":
Physics2D.gravity = new Vector2(0f, 9.81f);
Debug.Log("Gravity is Up");
break;
}
}
However I can't get the trigger event to register when my player passes through the triggers. I've combed through tutorials and done/checked everything I could think of and it still doesn't do anything. Also I've tested the gravity commands via certain inputs and they work just fine.
Answer by MewEight · Mar 23, 2016 at 02:36 AM
OnTriggerEnter2D Try this maybe. I had this problem last time too when handling with 2D. OnTriggerEnter2D will use your 2d colliders while OnTriggerEnter uses your 3d colliders
Thank you. This fixed it completely. I'll have to remember that unity treats 2D differently in some cases.