Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class NavAgent : MonoBehaviour {
NavMeshAgent myNavAgent;
[SerializeField]
NavPoint[] myNavPoints;
[SerializeField]
int navIndex = 0;
[SerializeField]
private float PatrolTime = 2f;
[SerializeField]
private float IdleTime = NavPoint;
[SerializeField]
private float PauseTime;
[SerializeField]
private GameObject isPatrol;
//[SerializeField]
//private GameObject isPaused;
private float timePassed = 0.0f;
// IdleState color
public Color darkGreen = new Color32(16, 88, 0, 255);
public float GetTimer()
{
return timePassed;
}
public float GetPatrolTime()
{
return PatrolTime;
}
public float GetIdleTime()
{
return IdleTime;
}
public GameObject GetPatrol()
{
return isPatrol;
}
// Use this for initialization
void Start()
{
ResetTimeSinceLastTransition();
myNavAgent = GetComponent("NavMeshAgent") as NavMeshAgent;
navIndex = 0;
FindDestination();
}
// Update is called once per frame
void Update()
{
// Update variable for time elapsed.
timePassed += Time.deltaTime;
}
public void ResetTimeSinceLastTransition()
{
// Reset time passed to zero.
timePassed = 0.0f;
}
// Use this for initialization
void FindDestination()
{
Vector3 newTravelPosition = myNavPoints[navIndex].transform.position;
myNavAgent.SetDestination(newTravelPosition);
}
void OnTriggerEnter()
{
++navIndex;
if (navIndex >= myNavPoints.Length)
{
navIndex = 0;
}
FindDestination();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment