x


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!

more ▼

asked Nov 30 '11 at 11:59 AM

nickjeu gravatar image

nickjeu
16 1 1 2

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.

Dec 02 '11 at 08:33 PM dannyskim

danny, think you just misread the {}s, that's an empty Update() function before OnTriggerEnter(). :)

Dec 02 '11 at 08:36 PM WillTAtl

Haha that's what happens when you stare at code all day my mistake. Have you tried using incollisionenter instead? I'm assuming 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?

Dec 02 '11 at 09:00 PM dannyskim
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x356
x102
x10

asked: Nov 30 '11 at 11:59 AM

Seen: 541 times

Last Updated: Dec 02 '11 at 09:00 PM