Animation of my enemies dont stop in my FPS game
Hi, I am making an FPS game. The problem is when I kill the enemy, the run animation doesn't stop ,however some enemies stop run animation after death but the shoot animation in them doesnt stop. Shooting Enemy Script-->
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ShootingEnemy : Enemy
{
public AudioSource DeathSound;
public NavMeshAgent Agent;
public float ShootingInterval = 4f;
private Player player;
private float ShootingTimer;
public float ChasingTimer;
public int ChasingInterval;
public Camera PlayerCam;
public int ShootingDistance = 10;
public float ChasingDistance = 25f;
public GameObject EnemyAim;
private Animator myAnim = null;
public GameObject SEnemy;
public float DisTimer=2f;
bool kld = false;
// Start is called before the first frame update
void Start()
{
myAnim = SEnemy.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Player>();
Agent = GetComponent<NavMeshAgent>();
ShootingTimer = Random.Range(0, ShootingInterval);
Agent.SetDestination(PlayerCam.transform.position);
}
// Update is called once per frame
void Update()
{
if (player.killed)
{
Agent.enabled = false;
this.enabled = false;
myAnim.SetBool("Shoot", false);
myAnim.SetBool("Near", false);
GetComponent<Rigidbody>().isKinematic = true;
}
ShootingTimer -= Time.deltaTime;
if (ShootingTimer <= 0 &&Vector3.Distance(transform.position,player.transform.position)<=ShootingDistance)
{
myAnim.SetBool("Shoot", true);
ShootingTimer = ShootingInterval;
GameObject Bullet = ObjectPoolingManager.Instance.GetBullet(false);
Bullet.transform.position = EnemyAim.transform.position;
Bullet.transform.forward = (PlayerCam.transform.position - EnemyAim.transform.position).normalized;
Agent.SetDestination(PlayerCam.transform.position);
}
else myAnim.SetBool("Shoot", false);
ChasingTimer -= Time.deltaTime;
if (ChasingTimer <= 0 && Vector3.Distance(transform.position,PlayerCam.transform.position)<=ChasingDistance)
{
myAnim.SetBool("Near", true);
ChasingTimer = ChasingInterval;
Agent.SetDestination(PlayerCam.transform.position);
}
else myAnim.SetBool("Near", false);
}
protected override void OnKill()
{
base.OnKill();
DeathSound.Play();
Agent.enabled = false;
this.enabled = false;
transform.localEulerAngles = new Vector3(10, transform.localEulerAngles.y, transform.localEulerAngles.z);
}
public void Dest()
{
SEnemy.gameObject.SetActive(false);
}
}
Comment