- Home /
How can i pay a animation again and agan?
I wanna make an endless runner game, and I want to increase the player speed every time the player's score is divisible by 50. I created an animated text that I'd like to appear every time this happens. How can I play it again, when the player's score rises to 100 or 150, and when the animation ends how can I make it jump back to its original place and only appear again when the score is as previously described? I tryd this metod but its call one time animation.
if((ScoreManager.instance.playerscore)%50 == 0) { speedanimation.GetComponent().Play("speedup"); }
Answer by javiolvecal · May 04, 2020 at 07:49 PM
@Attila23 I'm not sure if I understand correctly your problem, you have a score, and every time it reaches 50, 100, 150, 200 you want to play an animation of a text in the screen, but it only plays the first time.
I use a "trick" to this situations, I have an animator with only an animation (an state I mean) inside. What I do is create a script with a public void that diseable the Animator Component, then I call this void in an event in the animation.
public Animator Anim;
public void DesactAnimator(){
Anim.enabled = false;
}
To call this void in the animation, go to "Animation" window, hit the "Add Event" (1 in picture), it will create an event in the dopesheet (2 in picture), select it, then you must change "Function" in the inspector to the void that we created in the previous script (3 in picture). Now, move the event from the dopesheet (2) to the end of the animation, this will make the animator get diseable once the animation has ended. Now you only have to enable the loop in the animation from the Assets and every time you want to enable that text in the screen you only have to enable the Animator through code:
Animator.enabled = true;
REMEBER TO DISEABLE THE ANIMATOR COMPONENT AT THE START OF THE GAME, if you don't do that the animation of the text will Play every time you start the game, and we don't want that :)
I really hope this can help you, good luck with your game!! :D
To change the speed you must go to the animator state and acces the "speed" variable and change it to a higher variable :)
Pd: Sorry about my bad english (Im spanish) :/
Your answer
Follow this Question
Related Questions
Jump animation with a little bounce like towerfall 0 Answers
Why is this duplicate object not behaving like the original? 2 Answers
Changing how my character looks depending on his current lifes. 2 Answers
Mirrored animation doesnt rotate correctly 0 Answers
Run smooth continuous rotation animation of spinner using animator 1 Answer