I wrote my own waypoint script that currently only has 2 waypoints attached to it, i will add more once i iron out this annoying bug.
when my code hits the OnTriggerEnter function I have the console output what waypoint it is currently on. Each time my object hits the trigger it will execute the code 2 or 3 times.
this causes it to skip over multiple waypoints if I have them.
also once it hits the last waypoint and the waypointIndex is equal to the waypointarray.Length it fails to reset back to zero
is there a way to have the OnTriggerEnter function to only be called once every 2 seconds or so?
it seems that the engine executes the code so far that the OnTriggerEnter function gets called several times before it acquires a new target…
here is my console log.
The Current Waypoint is:0
UnityEngine.MonoBehaviour:print(Object)
Waypoint:OnTriggerEnter(Collider) (at Assets/Waypoint.js:36)
******* at this point the object hits the trigger and i get this in the Console instantly
The Current Waypoint is:1
UnityEngine.MonoBehaviour:print(Object)
Waypoint:OnTriggerEnter(Collider) (at Assets/Waypoint.js:36)
The Current Waypoint is:2
UnityEngine.MonoBehaviour:print(Object)
Waypoint:OnTriggerEnter(Collider) (at Assets/Waypoint.js:36)
The Current Waypoint is:3
UnityEngine.MonoBehaviour:print(Object)
Waypoint:OnTriggerEnter(Collider) (at Assets/Waypoint.js:36)
var target : Transform;
var waypoints : Transform[];
var moveSpeed : double;
var waypointIndex : int;
function Awake()
{
if(!target)
{
target = waypoints[0];
}
waypointIndex = 0;
print("The Current Waypoint is:" + waypointIndex);
}
function Update ()
{
transform.LookAt(target);
transform.Translate (0,0,Time.deltaTime * moveSpeed);
}
function OnTriggerEnter (gameObject : Collider)
{
if(waypointIndex == waypoints.Length)
{
waypointIndex = 0;
print("The Current Waypoint is:" + waypointIndex);
}
target = waypoints[waypointIndex];
waypointIndex++;
print("The Current Waypoint is:" + waypointIndex);
}
any advice or information about this would be very helpful
thanks