2015-11-07 17:20:12 -05:00

39 lines
729 B
C#

using UnityEngine;
using System.Collections;
public class monsterAI : MonoBehaviour
{
public GameObject player;
private Transform target;
public float deadlyDistance;
private NavMeshAgent agent;
// Use this for initialization
void Start ()
{
target = player.transform;
agent = gameObject.GetComponent<NavMeshAgent> ();
agent.SetDestination (target.position);
}
// Update is called once per frame
void Update ()
{
if (IsAtDeadlyDistance ()) {
// Kill the player
}
agent.SetDestination (target.position);
}
// Check is the current distance is deadly for the target
bool IsAtDeadlyDistance ()
{
return (Vector3.Distance (target.position, transform.position) <= deadlyDistance);
}
}