It’s supposed to randomly choose one of the nine bools that are setup with the animations, but it chooses all at once and activates all the bools. Why does this happen and how do I randomly play one and only one of the nine animations??
We will need more context to find the problem. We need to see how this is being called and what you’re doing with these bools, because as it is now nothing appears to be done with the animations.
I do note in the commented-out code that you’re using the Animation class, which is old and deprecated. It’s been replaced by the Macanim animation system, which uses the class Animator and works differently.
As I mentioned the bools are linked to an animation. In the animator, the link from the “Any state” node to each death animation is connected via each corresponding bool.
So to phrase it differently the question is how do I randomly make 1 of these booleans true? forget the animations. There are 9 bools in total. I’ve tried using Random Range as you can see, but as I wrote before it turns on all of them at once
Do you reset them all to false before randomly activating one? Depending on where you’re calling DeathAnims(), it might activate them all one by one in very few frames, so that it looks like it’s activating them all at once.
Also, a switch() instead of a lot of ifs might be more readable in this case.
Setting them to false in Start() is not enough if you’re calling DeathAnims() more than once. Without taking a look at the rest of your code (specifically, where and how you’re using DeathAnims) it is pretty much impossible to tell what the problem is.
Using a switch works exactly the same as ifs, only it’s a bit cleaner:
rand = Random.Range(0, 9);
switch (rand)
{
case 1:
hipshakeDeath = true;
break;
case 2:
xploDeath = true;
break;
case 3:
headSlapDeath = true;
break;
case 4:
crouchDeath = true;
break;
case 5:
saluteDeath = true;
break;
case 6:
dance = true;
break;
case 7:
sprald = true;
break;
case 8:
dead = true;
break;
}
Thats what I wanted to post:
“Your DeathAnim() could also get a random number and pass it into switchcase to choose one of them.” So… gg u were first