void Awake() { // Set up the references. player = GameObject.FindGameObjectWithTag("Player").transform; playerHealth = player.GetComponent <PlayerHealth> (); enemyHealth = GetComponent <TutorialEnemyHealth> (); nav = GetComponent <UnityEngine.AI.NavMeshAgent> (); }
float timer; // Timer for counting up to the next attack. void Awake() { // Setting up the references. player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth> (); enemyHealth = GetComponent <TutorialEnemyHealth>(); anim = GetComponent <Animator> (); audio = GetComponent <Zombie_Audio>(); }
public void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); BossHealth bossHealth = shootHit.collider.GetComponent <BossHealth> (); TutorialEnemyHealth tutorialEnemyHealth = shootHit.collider.GetComponent <TutorialEnemyHealth> (); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } if (bossHealth != null) { bossHealth.TakeDamage(damagePerShot, shootHit.point); } if (tutorialEnemyHealth != null) { tutorialEnemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }