mirror of
https://github.com/ConjureETS/EscapeTheRoom.git
synced 2026-03-24 01:00:58 +00:00
39 lines
729 B
C#
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);
|
|
}
|
|
}
|