My character is playing a idle animation (using animator) which is set to loop, when I click the button I would like to play a random animation (which it does (a random jump animation)).
If I click the button again nothing will happen because the animation is now at the jump state how would I code this to go back to the idle state so when the user clicks the button it will choose a random jump animation again.
Heres my code:
using UnityEngine;
using System.Collections;
public class waypointMessage : MonoBehaviour {
Animator anim;//public or private
int pickAnumber;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
void OnGUI ()
{
if(GUI.Button(new Rect(20,40,150,40), "Play different animation"))
{
pickAnumber = Random.Range(1,3);//exclusive never prints the last only goes 1 to 2
Debug.Log (pickAnumber);
//randJumpInt is the parameter in animator
//pickAnumber randon number from 1 to 2 from above
anim.SetInteger ("randJumpInt", pickAnumber);
//how do I go back to the original state idle animation
}
}
}