I’m making a game and I have made a bool parameter in Animator controller named “Point” . I have a player with four animation clips , and I want my player to randomly play an animation when collide with the “Point”.
public List myAnimations = new List();
(Add animations)
myAnimations[Random.Range(0, myAnimations.Count - 1)].Play
animator.SetBool(animator.parameters[Random.Range(0, animator.parameters.Length)].name, true);
maybe this can help you
I don’t know if there’s a good way to do it with just one parameter.
What I would do is make 4 bool parameters, called like ‘Point1’, ‘Point2’, ‘Point3’, and ‘Point4’.
Then I would set the animator to go from any state to each of the animations, each one using a different parameter.
Then I would just set up in a player controller script to do something like this.
OnCollisionEnter(Collider other)
{
if(other.tag == "Point")
{
switch(Random.RandomRange(0,3))
{
case(0):
SetBool("Point1");
break;
case(1):
SetBool("Point2");
break;
case(2):
SetBool("Point3");
break;
case(3):
SetBool("Point4");
break;
}
}
}
public GameObject Bottle;
public List anim =new List ();
public void StartAnimation ()
{
int rand = Random.Range (0, anim.Count);
Debug.Log (rand);
Bottle.GetComponent<Animation> ().Play (anim[rand].name);
}