I have an enemy that breaths fire and I had a NullReferenceException.
I added ;
if(EnemyHealthManager != null)
to deal with it and while the enemy does breath fire, it does not give damage
What could the problem be?
public class MegalothAttack : MonoBehaviour
{
public float timeBetweenAttacks = 0.5f;
public int attackDamage = 25;
GameObject player;
PlayerHealth playerHealth;
EnemyHealthManager EnemyHealthManager;
bool playerInRange;
float timer;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player");
playerHealth = player.GetComponent ();
EnemyHealthManager = GetComponent();
//anim = GetComponent ();
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player") {
playerInRange = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Player") {
playerInRange = false;
}
}
void Update ()
{
timer += Time.deltaTime;
if(EnemyHealthManager != null) <<= timeBetweenAttacks && playerInRange && EnemyHealthManager.currentHealth > 0) << 0) {
playerHealth.TakeDamage (attackDamage);
}
}
}
↧