Created
October 28, 2017 22:04
-
-
Save JonathanYin/4d7eadace164ae251ef7032134c496eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class EnemyMovement : MonoBehaviour | |
{ | |
Transform player; | |
PlayerHealth playerHealth; | |
EnemyHealth enemyHealth; | |
UnityEngine.AI.NavMeshAgent nav; | |
public float speed = 6f; | |
void Start () | |
{ | |
nav.speed = speed; | |
} | |
void Awake () | |
{ | |
player = GameObject.FindGameObjectWithTag ("Player").transform; | |
playerHealth = player.GetComponent <PlayerHealth> (); | |
enemyHealth = GetComponent <EnemyHealth> (); | |
nav = GetComponent <UnityEngine.AI.NavMeshAgent> (); | |
} | |
void Update () | |
{ | |
if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0) | |
{ | |
nav.SetDestination (player.position); | |
} | |
else | |
{ | |
nav.enabled = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment