Hello- I've been working on a waypoint system and have run into some trouble. The script should move *unit* to *waypoint*, which is then destroyed and *waypoint2* is turned into *waypoint*, and the process is then repeated. However, while it reaches *waypoint* fine, *waypoint2* will not turn into *waypoint*- it simply stops moving at *waypoint*. Any ideas as to why this is happening? Many thanks for any light you can shed on this!
var unit: GameObject;
var waypoint: GameObject;
var waypoint2: GameObject;
var duration: float;
var collision: Collision;
private var starttime: float;
function start(){
//sets start time for comparison on motion
starttime = Time.time;
}
function Update () {
//detects for the presence of a waypoint
if (GameObject.Find("waypoint") != null){
//if a waypoint is present, move it to its location over the given duration
var startpos: Vector3 = unit.transform.position;
var endpos: Vector3 = waypoint.transform.position;
transform.position = Vector3.Lerp(startpos, endpos, (Time.time - starttime)/duration);
}
}
function OnCollisionEnter(collision : Collision)
{
//when the unit collides with the waypoint, destroy it
if(collision.collider.gameObject.name == "waypoint")
{
Destroy(waypoint.gameObject);
waypoint2.name = "waypoint";
waypoint = waypoint2;
starttime = Time.time;
}
}
Oh, and another thing (although I'm probably not quite thinking clearly right now, it seems like it *should* be pretty simple, although I for some reason can't think it through...)- does anyone have any ideas as to how to make this unit-specific? Meaning that when a unit is 'selected' the waypoints (placed in gameplay) are applied to that unit in particular, since I'm going to be dealing with a bunch of them... Any ideas? Thanks!
↧