Activate an animation when a certain score reached
If I want to show an animation when a certain score is reached only once, what would be the best way about doing it?
By trying to activate the animation with just the condition of the score being equal, the animation repeats itself several times (loop deactivated).
So then I added a boolean which switches itself to make the animation go off once, but sadly, this didn't work, but why?
This is my code for the animator:
void Update () {
score = enem.GetScore();
anim.SetInteger("score", score);
Check();
}
private void Check()
{
for (int i = 0; i < levels.Length; i++)
{
if (score == levels[i])
{
SetBool(i);
}
}
}
void SetBool(int id)
{
switch (id)
{
case 0:
anim.SetBool("x", true);
break;
case 1:
anim.SetBool("bool02", true);
break;
case 2:
anim.SetBool("bool03", true);
break;
default:
break;
}
}
As you may tell, I have set it up for multiple cases, since I want different animations to activate at different scores.
Basically what I do in the animator is ask at the transition whether the score is equal to what is expected and the bool is false, but it isn't working! :( The animation never activates
How would you go about setting this up?
Is there a better method?
Please help!
Use Debug.Log to try and isolate the issue. Are your anim.SetBool statements getting called? It's difficult for anyone else to know exactly what could be going wrong, as we don't have the whole picture.
@RyanDiCenzo Thanks for the suggestion, should've thought of it before even bothering posting this question! I finally solved it by just putting the Check method at the beginning of update so that there's one chance for the bool to be false. Thanks! :)