This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Project Undercover/Assets/Scripts/SimpleNPCBehavior.cs
2017-09-18 15:04:18 -05:00

35 lines
No EOL
770 B
C#

using UnityEngine;
using System.Collections;
using UnityEngine.AI;
public class SimpleNPCBehavior : MonoBehaviour
{
public int updateTime;
private Vector3 target;
private NavMeshAgent agent;
enum State {
idle,
walking,
talking
};
void Start()
{
this.GetComponent<Renderer> ().material.color = Random.ColorHSV (0f, 1f, 1f, 1f, 0f, 1f);
target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value));
agent = GetComponent<NavMeshAgent> ();
}
void Update()
{
// Every updateTime seconds set new target position
if (Time.fixedTime % updateTime == 0) {
if ((int) (3.0f * Random.value) == 0)
target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value));
}
agent.destination = target;
}
}