hello guys, i want to play the hurt animation when my character hit collider, the animation start but my character Hit Animation play endlessly. I dont know how to make him back to previous state of animation, here my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerControl : MonoBehaviour {
private Vector2 Targetpos;
public float Yincrement;
public float speed;
public float maxHeight;
public float minHeight;
public int health ;
public GameObject effect;
private Animator anim;
// Use this for initialization
private void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (health <= 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
transform.position = Vector2.MoveTowards(transform.position, Targetpos, speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.UpArrow)&&transform.position.y<maxHeight)
{
Instantiate(effect, transform.position, Quaternion.identity);
Targetpos = new Vector2(transform.position.x,transform.position.y + Yincrement);
}
if (Input.GetKeyDown(KeyCode.DownArrow) && transform.position.y > minHeight)
{
Instantiate(effect, transform.position, Quaternion.identity);
Targetpos = new Vector2(transform.position.x, transform.position.y - Yincrement);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Enemy"))
{
anim.SetBool("IsHurt",true);
}
}
IEnumerator Delay()
{
yield return new WaitForSeconds(1.0f);
anim.SetBool("IsHurt", false);
}
}