Hey I’m getting a NullReferenceException error and not sure why… Any help would be appreciated!
Thanks!
Error line :
“anim.SetBool (“Dead”, true);”
using UnityEngine;
using System.Collections;
public class EnemyHelthManager : MonoBehaviour {
public int MaxHealth;
public int CurrentHealth;
public GameObject bloodpop;
private bool Dead;
private Animator anim;
// Use this for initialization
void Start () {
CurrentHealth = MaxHealth;
}
// Update is called once per frame
void Update () {
if (CurrentHealth <= 0)
{
Dead = true;
anim.SetBool ("Dead", true);
}
if (CurrentHealth < MaxHealth)
Instantiate (bloodpop, transform.position, transform.rotation);
}
public IEnumerator DeathAnim()
{
if (Dead == true)
{
yield return new WaitForSeconds (3);
Destroy (gameObject);
}
}
public void HurtEnemy(int damageToGive)
{
CurrentHealth -= damageToGive;
GetComponent<AudioSource>().Play();
}
public void SetMaxHealth ()
{
CurrentHealth = MaxHealth;
}
}