I have a script where you shoot a gun at a enemy the health goes to zero it should play a animation…
However of course its not playing
It just stops all animations all together and just sits there.
Also the floating I am aware of I haven’t figured out how to keep it on the ground yet
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Zombie : MonoBehaviour
{
public GameObject ThePlayer;
public float TargetDistance;
public float AllowedRange = 10;
public GameObject TheEnemy;
public float EnemySpeed;
public int AttackTrigger;
public RaycastHit Shot;
void Update()
{
transform.LookAt(ThePlayer.transform);
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
{
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange)
{
EnemySpeed = 0.01f;
if (AttackTrigger == 0)
{
TheEnemy.GetComponent<Animation>().Play("Walking");
transform.position = Vector3.MoveTowards(transform.position, ThePlayer.transform.position, EnemySpeed);
}
}
else
{
EnemySpeed = 0;
TheEnemy.GetComponent<Animation>().Play("Idle");
}
}
if (EnemyHealth <= 0)
{
TheEnemy.GetComponent<Animation>().Play("Death");
Debug.Log("Died");
}
if (AttackTrigger == 1)
{
EnemySpeed = 0;
TheEnemy.GetComponent<Animation>().Play("Attacking");
Debug.Log("working");
}
}
public int EnemyHealth = 10;
void DeductPoints(int DamageAmount)
{
EnemyHealth -= DamageAmount;
}
void OnTriggerEnter()
{
AttackTrigger = 1;
Debug.Log("working");
}
void OnTriggerExit()
{
AttackTrigger = 0;
Debug.Log("Not working");
}
}
