Hello.
i am a newbie and have a simple question.
I have a hurt animation on the enemy that is triggered when the player shoots it. Suppose the enemy is chasing the player and the player shoots it while chasing him, the hurt animation is triggered. However, i would like to freeze the enemy movement(freeze the chase) when the hurt animation is triggered. This might be a simple fix, but i cant seem to get it done.
Here is the code that is responsible for the enemy movement
public class NewEnemyScript : MonoBehaviour
{
//use holster master as the player target
[SerializeField] private Transform playerTarget;
[SerializeField] private float attackRange;
[SerializeField] private float alertRange;
[SerializeField] private float moveSpeed;
[SerializeField] private Animator anim;
void Update()
{
if(Vector3.Distance(playerTarget.position,this.transform.position)attackRange)
{
this.transform.Translate(0, 0, moveSpeed);
anim.SetBool("isRunning", true);
anim.SetBool("isAttack", false);
}
else
{
anim.SetBool("isAttack", true);
anim.SetBool("isRunning", false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isAttack", false);
anim.SetBool("isRunning", false);
}
}
i have an other script named health that is attached to the enemy and the hurt animation is triggered here when the bullet is collided with the enemy along with a deduction in health
public class NewHealth : MonoBehaviour
{
[SerializeField] private float enemyHealth = 100f;
[SerializeField] private Animator animator;
private bool isDead = false;
[SerializeField] private float deductHealth = 10f;
void Update()
{
if (!isDead)
{
if (enemyHealth <= 0)
{
enemyDead();
}
}
}
public void DeductHealth()
{
if (!isDead)
{
enemyHealth -= deductHealth;
animator.SetTrigger("Hurt");
}
}
void enemyDead()
{
Destroy(gameObject, 5);
animator.SetBool("isDead", true);
isDead = true;
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag=="Bullet")
{
DeductHealth();
Destroy(other.gameObject);
Debug.Log("Hurt");
}
}
Here is the animator window![alt text][1]
[1]: /storage/temp/183476-animator.jpg
any help would be greatly appreciated. Thank you for your time.
↧