Created
August 30, 2017 17:29
-
-
Save unity3dcollege/ea0b71e262b8c96ec434060aba63c8a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEngine.AI; | |
public class AIBrain : CharacterBrain | |
{ | |
public AIBrain(NavMeshAgent navMeshAgent) : base(navMeshAgent) | |
{ | |
navMeshAgent.GetComponent<Renderer>().material.color = Color.white; | |
} | |
public override void Tick() | |
{ | |
if (!navMeshAgent.hasPath || navMeshAgent.pathStatus != NavMeshPathStatus.PathComplete) | |
{ | |
Vector3 position = GetRandomPosition(); | |
navMeshAgent.SetDestination(position); | |
} | |
} | |
private Vector3 GetRandomPosition() | |
{ | |
var randomOffset = new Vector3( | |
UnityEngine.Random.Range(-5f, 5f), | |
0f, | |
UnityEngine.Random.Range(-5f, 5f)); | |
return navMeshAgent.transform.position + randomOffset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment