- Home /
Build and Run is breaking my triggers!
enter code hereThe title sums up my problem. I have a game that seems to run fine when I try to play it through the play button at the top of the screen. All of my scripts run just fine and no errors come up. Unfortunately, now that the game is done and we're ready to put it in the quarterly art show, we've run into a snag.
When we hit build and run, some of the triggers break.
The first simply triggers an animation on a swinging wrecking ball. I know the animation works, because another script that triggers it when I left click (for testing purposes) can sometimes trigger it. Then again some times I build the project it can't. I havn't changed anything, but the results sometimes differ!
function Update () {
}
function OnTriggerEnter (other : Collider) {
var swing : GameObject = GameObject.Find("Wreck");
swing.animation.Play("wreck_swing");
}
The second is similar. Its a trigger over a portion of walkway that drops out from under the player. Again, It can be triggered with click commands, but the trigger seems to fail entirely.
function Update () {
}
function OnTriggerEnter (other : Collider) {
var walkway : GameObject = GameObject.Find("Walkway");
walkway.animation.Play("drop");
}
I almost hope I'm doing something wrong. At least that way I can fix it and never have to deal with this again.
Thanks for your help in advance!
I'm not sure if this is a mistake on your part, but I don't ever use OnTriggerEnter inside of the Update loop, I'm surprised that it even compiles. Your code inside OnTriggerEnter seems perfectly legitimate, save for the fact that it's in update, and you should almost never use GameObject.Find inside of update.
Even for desktop platforms, it is highly suggested to call GameObject.Find on a SINGLE event, and cache the component rather than refreshing the reference every frame. I can see that this probably wasn't your intention, but just a forewarning.
danny, think you just misread the {}s, that's an empty Update() function before OnTriggerEnter(). :)
Haha that's what happens when you stare at code all day my mistake. Have you tried using incollisionenter ins$$anonymous$$d? I'm assu$$anonymous$$g since they sometimes work that the istrigger is checked in the inspector? Have you tried putting a print to make sure that ontrigger is getting called?
Any luck figuring this out. I am having the same problem. Triggers work in editor but not in build.
Your answer
Follow this Question
Related Questions
OnTriggerEnter doesnt see enemy 1 Answer
Can I make A trigger, Trigger the OnTriggerEnter Function 1 Answer
Updating a Value in OnTriggerEnter and Returning That Value Immediately... 0 Answers
How do I ignore trigger objects for collision? 0 Answers
show different textures when trigged entered thrice 2 Answers