- Home /
How to count how many times a cetain animation has been played.
Dear people of community, I am creating a game where I need help to count how many times a certain animation has been played? So I could create a scoreboard out of that count. Any ideas?
Thank you all!
$$anonymous$$ecanim or Legacy animation system?
Also 2D or 3D game?
Have you already started coding or (as you've been a member here for only a couple of hours) are you starting from scratch and don't know any coding?
It's just Unity Answers might not be the best place to start for you.
Thanks for replaying. It's a 3D mobile game. Basically, every time the screen is touched, animation is played. Now, I do know how to count number of touches, but the problem is that animation is supposed to loop as long as screen is touched.
Answer by Mmmpies · Jan 11, 2015 at 09:57 PM
Hmmm, don't know the animation system well enough but if looping then the animation must have a duration.
Find that, for example let's say the animation takes 1.49 seconds. Then let's say you've got a bool that is true if the animation is playing, we'll call the playMyAnimaton, also hold an int playedMyAnimation and increment that:
playedMyAnimation ++;
When that bool is set to true from false record the animation start time with a float like animStartTime.
animStartTime = Time.time;
then in update the playMyAnimation is true check if the current time is > animStartTime + 1.49f
if(Time.time > startAnimTime + 1.49f)
{
animStartTime = Time.time;
playedMyAnimation ++;
}
When you stop playing the animation set the bool to false.
playedMyAnimation should equal the amount of times played.
This is C# and you need to let us know what you're language you're coding in as well. Sorry it's a bit vague but give us as much information as you can so the answer can be tailored to what you want.
there are probably better ways of doing this but it should work.
Your answer
Follow this Question
Related Questions
How to save a high score 2 Answers
Animation Play On Bullet Shot 1 Answer
Problem with Collecting Stars 1 Answer
Score Points and Animation 0 Answers
Highscore with points and time 1 Answer