- Home /
Question by
Nickolas21 · Jun 06, 2011 at 06:23 PM ·
animationrepeat
I want the animation not to play if it is already playing...
How can I prevent my animation from playing if it is already playing? This is my C# Script:
void ReloadGun () { bullets = 0;
if (!gunOn) {
UnHolsterGun();
}
else if (!inTransition && !inFire) {
animation.CrossFade(reloadAnimation.name);
bullets = clipSize;
SendMessage("OnReload");
}
}
This is just the reload part...
Comment
In general Play/CrossFade doesn't restart the animation if it is currently playing. That's why you see scripts with if(speed>0) Play("walk")
that aren't constantly restarting walk.
Answer by UnityJP · Jun 07, 2011 at 11:11 PM
You could try doing a check if it is playing beforehand
void ReloadGun () {
bullets = 0;
if (!gunOn) {
UnHolsterGun();
}
else if (!inTransition && !inFire) {
if(!animation.IsPlaying(reloadAnimation.name)) //If its not playing
animation.CrossFade(reloadAnimation.name);
bullets = clipSize;
SendMessage("OnReload");
}
}
Your answer
Follow this Question
Related Questions
How To Get Current Animation Name 3 Answers
Flash raw animation data to Unity 0 Answers
play only one door animation 1 Answer
how to collide .fbx animation in unity 0 Answers
Humanoid animation issue 0 Answers