- Home /
Having problems with 2d collision triggers (javascript)
So I've watched lots of tutorials and I have no idea what my problem could be. What I am trying to do is that whenever an object passes over a certain spot on the map, something will happen (a debug.log is what I am using for now). To do this, every object I want to be able to trigger the area, I've added a "box collider 2d" without the "is trigger" checkmarked. I then created empty objects at the spots I needed them and added "box collider 2d" to all of them and checked the "is trigger" box. I then wrote a script, and wrote in it:
pragma strict
function OnTriggerEnter() {
Debug.Log("It worked");
}
I then attached this script to all of the empty objects. When I test to see if this works, nothing happens.
Extra information that might be of use:
Every object that needs to trigger the empty object is moving using Itween. The script for that is
iTween.MoveTo(gameObject,{"y": Variables.bikeDestination, "easetype": "linear","time": Variables.travelTime });
I created an empty object with no components attached, and dragged all of my triggers onto it to keep things more organized.
Answer by Adamcbrz · Mar 18, 2014 at 01:37 AM
I had this same problem. You have to use OnTriggerEnter2D
Well that was a big waste of time trying to figure out what my problem was while there was such simple solution. Thank you so much.
Your answer
Follow this Question
Related Questions
Different results between "ContactPoint" and "ContactPoint2D" 0 Answers
Collision with renderer.enabled? 0 Answers
Scoring Issue 0 Answers
Trigger Enter and Exit not working properly? 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers