Skip to content

Instantly share code, notes, and snippets.

@rbreve
Created October 8, 2014 03:34
Show Gist options
  • Save rbreve/0cbd9a7c7bb3a935f058 to your computer and use it in GitHub Desktop.
Save rbreve/0cbd9a7c7bb3a935f058 to your computer and use it in GitHub Desktop.
Unity3D animator play once
public IEnumerator PlayOneShot ( string paramName )
{
anim.SetBool( paramName, true );
yield return new WaitForSeconds (anim.GetCurrentAnimatorStateInfo(0).length/2);
anim.SetBool( paramName, false );
}
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
wstate = Animator.StringToHash("Base Layer.walking");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Space)){
StartCoroutine( PlayOneShot("isKicking") );
//anim.SetBool("isKicking", true);
Debug.Log ("kick");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment