Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created August 30, 2017 17:29
Show Gist options
  • Save unity3dcollege/ea0b71e262b8c96ec434060aba63c8a7 to your computer and use it in GitHub Desktop.
Save unity3dcollege/ea0b71e262b8c96ec434060aba63c8a7 to your computer and use it in GitHub Desktop.
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