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

28 lines
655 B
C#
Raw Normal View History

using UnityEngine;
using System.Collections;
2017-09-18 12:43:50 -05:00
using UnityEngine.AI;
public class SimpleNPCBehavior : MonoBehaviour
{
public float moveSpeed;
public int updateTime;
private Vector3 target;
2017-09-18 12:43:50 -05:00
private NavMeshAgent agent;
void Start()
{
2017-09-13 17:29:22 -05:00
target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value));
2017-09-18 12:43:50 -05:00
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));
}
2017-09-18 12:43:50 -05:00
agent.destination = target;
}
}