- Home /
How to make stop NPC from looping through waypoints.
I'm using a script from this forum post
http://forum.unity3d.com/threads/54678-A-Waypoint-Script-Explained-in-Super-Detail!
When the character gets to the last waypoint it turns around and goes to the firs one. HO can I modify this so that the character stops?
Comment
Best Answer
Answer by Vandarthul · Apr 28, 2014 at 03:26 AM
private var stopWaypointLoop: boolean;
function Start ()
{
functionState = 0;
stopWaypointLoo = false;
}
function Update ()
{
if(stopWaypointLoop == false)
{
if (functionState == 0)
{
Accell ();
}
if (functionState == 1)
{
Slow ();
}
waypoint = waypoints[WPindexPointer];
}
}
function OnTriggerEnter ()
{
functionState = 1;
WPindexPointer++;
if (WPindexPointer >= waypoints.Length)
{
stopWaypointLoop = true; // when the NPC reaches last waypoint, with this code we stop it from doing that.
WPindexPointer = 0; // NPC keeps going on waypoints.
}
}
Please mark the answer as "accepted" and close your topic if you find the solution of your problem.
Your answer

Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Multiple Cars not working 1 Answer
Mecanim Making an NPC walk 1 Answer
Distribute terrain in zones 3 Answers
Animate Character movement? 1 Answer