- Home /
Stop Door Loop
I have a scene where I hit a switch and a door opens. My gun is a stream of particles. The problem I have is when I constantly shoot the switch, the door opens then loops and opens etc.. How can I fix this so that it only plays the door animation once? I've tried things like booleans but that doesn't work. Here is the script applied to the switch:
var TheDoor : GameObject;
function OnParticleCollision () {
TheDoor.animation.Play("opendoor"); }
Answer by iwaldrop · Feb 13, 2013 at 06:32 AM
You need to set the Animation Wrap Mode to Once or Clamp Forever, depending on your use case.
var TheDoor : GameObject;
function OnParticleCollision () {
TheDoor.animation.Play("opendoor"); TheDoor.animation.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once; }
The door still seems to go on a loop. Just remember, the gun is shooting a continuous stream of particles when I click.
Oh, well if that's the problem then you need to keep track of the state of the door. You can't just keep playing Open if it's already open!
private bool isOpen;
function OnParticleCollision ()
{
if (!isOpen)
{
TheDoor.animation.Play("opendoor");
isOpen = true;
}
}
Thanks it works!!! You might have noticed I ask a few newbish questions because I'm just trying to absorb all the javascript knowledge.
'Noob' questions are totally fine! Everybody starts somewhere. :)
Your answer
Follow this Question
Related Questions
Particle colision using shruiken 1 Answer
mouse click obj to initiate action, then locking the obj so action cant be repeated 1 Answer
Collision Detection for a Prefab? 3 Answers
Track debug - Object dissapears after collision 0 Answers
How to destroy a parent object when child object is collided 1 Answer