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”);
}
@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!!