I think I either have a misunderstanding of how triggers work, or maybe a code issue. Here’s what I’m trying to do:
I basically want to be able to detect when my camera is at certain stop points in my game. For each stop point I have created an empty gameobject and have added a RigidBody component and (no gravity) and a box collider that is set to isTrigger. When I move the camera between points I want a trigger to fire letting me know which point I’m at.
In my camera I assigned the following script:
function OnTriggerEnter (stopPoint : Collider) {
if(stopPoint.collider.name == “Point A”){
Debug.Log(“Camera is at Point A”);
}
}
My problem is that this works only on the first time the camera moves over the stop point trigger. Afterwards I get no other messages.
Based on my understanding of triggers I would assume every time the camera moved into the trigger area I would get a new message…
Yes that should be the case, that is of course assuming the camera leaves the trigger area completely before entering it again.
OK, after pulling every hair out last night testing this, here’s what I found.
Using the script above I noticed that the log message from a trigger event would post to the console once, and then not post again as I moved the camera around. But, if I cleared the message from the console between camera movements the message would always post as I moved around. So, after about 2 hours of discovering this I finally concluded that something must be up with the way the console posts debug messages, and decided to make boolean variables that would be changed when the camera hits a trigger… worked perfectly!!! So, at this point I now know that the triggers work as expected, but I’m wondering if there’s something flaky in how the console displays duplicate debug messages. Can someone from Unity chime in on this?
You’ll notice that the console window has a small Collapse button in the bar. With this option enabled, the window will avoid showing a sequence of identical repeated messages. This is often useful but it can trip you up in some cases, as you have seen.