- Home /
counting how many times a specific animation plays
Hello u unity users. How would you count how many times a specific animation plays from a random range of animations? In this case I want "swing" to play 5 Times, // then do something.
("Roll","spin","swing")
I tried your script, although it works,it just counts as fast as the random range generates its numbers. What I really need is to have a count for every time the specific animation plays. Any thoughts?
if (animation.Play(ur specific animation)) { counter +=1; }
Again your script works just fine.but same result, counter just keeps counting quicker than actual animations play. I think the issue is that random.range generates queued animations ahead of time and just keeps generating a massive queue and counts+1 as it climbs. Is this possible? I'm a bit out of my depth I think.
#pragma strict
#pragma downcast
var Anims = ["up","down"];
var $$anonymous$$odel: GameObject;
var speed =3;
var count : int;
function Update () {
Game();
}
function Game () {
var random:int = Random.Range(0,2);
if (random ==0){
animation.CrossFadeQueued("up");
count+=1;
}
if (random ==1){
animation.CrossFadeQueued("down");
}
}
Answer by thornekey · Jun 01, 2014 at 07:25 AM
you could have an int counter so after ever time the animation plays add one value to it like so:
public int counter = 0;
animation.Play(playur animation);
counter +=1;
or for a specific animation
if (animation.Play(ur specific animation)) {
counter +=1;
}
if(counter >= 5) {
//do ur thing
//reset the counter
counter == 0;
}
How can you get the animation ? When i enter animation.Play($$anonymous$$yAnim) it doesn't find the path to the specific animation...
Answer by sarusian · Jun 01, 2014 at 12:57 PM
public int counter = 0;
animation.Play();
if (animation.Play(theAnimation) {
counter += 1;
}
if(counter >= 5) {
//do ur thing
//reset the counter
counter == 0;
}
I answered first, It was submitted for approval, this system is so stupid, I have to wait until I get enough $$anonymous$$arma, and if someone answers others downvote for copying and a loose karma, its a vicious cycle.
you are such a liar. ive highlighted a certain thing called a time stamp in red.. -.-
LOO$$anonymous$$ AT THE TI$$anonymous$$E I ANSWERED 5 HOURS AGO. And your text is EXACTLY the same. Ive reported you.
you are pathetic.
Answer by Xx_Alanox_xX · Oct 21, 2017 at 06:04 PM
He even forgot to close the "()" x), thank you thorney !