OnTriggerEnter2D Problems. Not working.
I am new to Unity and I am trying to make a script that switches me to the next scene when I collide with the object, and it is not working. I've been searching everywhere for an answer for over an hour and I can't find anything that helps. Here is my code:
void OnTriggerEnter2D (Collider2D other){ if (other.gameObject.tag == "next") { Application.LoadLevel ("Level2"); } }
No, it is not called "Collider.cs". If anyone could help I would really appreciate it. :)
Answer by gro420 · Sep 04, 2015 at 05:26 PM
Nevermind, the problem was something very dumb. When I created the shape I thought that it automatically put a 2D Box Collider on it, but it actually put a 3D Collider, and I did not notice. Thanks for trying to help me @DiegoSLTS
Answer by DiegoSLTS · Sep 04, 2015 at 03:35 AM
Did you check the "IsTrigger" field of the collider in the inspector?
Does the other object have a collider too?
Does any of them have a RigidBody2D? For OnTriggerXXXX methods to be called at least one of the objects colliding has to have a RigidBody (for 3D and 2D versions of the methods).
Is the collision between the layers of the 2 objects checked in the physic's collision matrix? http://docs.unity3d.com/Manual/LayerBasedCollision.html
If none of those questions helped share more info, describe the objects colliding and maybe share some screenshots of the inspector when selecting them.
I can answer the questions but I cannot provide screenshots at the moment as I am not home. Both the objects have 2D Colliders, and the Player has a RigidBody2D and IsTrigger enabled (not on my character though, because if I enable it, it just falls through the ground for some odd reason).
I am not 100% sure about the last thing you talked about - the "physic's collision matrix". I will have a look at that as soon as I get home. Hopefully these answers can help you fix my problems, thank you for taking the time to try and help me, I appreciate it.
Your answer
Follow this Question
Related Questions
How to make my 2D character roll 0 Answers
What is the easiest way to enable 2D isometric grid-based pathfinding? 2 Answers
Weird artifacts appear on my 2D sprites. 0 Answers
Collition Coding not working 1 Answer
Can the new ParticleSystem Trigger Module access the particle's collision collider? 0 Answers