Hey, Im trying to add a new gameObject (empty) to a transform array thing (Im not to knowledgeable on how arrays work/what they are) and have a bot patrol between these empties, heres the code;
var WayPoint : Transform[];
private var CurrentWayPoint : int;
var Speed : float = 20.0;
Awake() VVVVVVV
WayPoint[0] = transform;
Update() VVVVVVV
if(CurrentWayPoint < WayPoint.length)
{
var target : Vector2 = WayPoint[CurrentWayPoint].position;
var moveDirection : Vector2 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
CurrentWayPoint++;
}
else
{
velocity = moveDirection.normalized * Speed;
}
}
else
{
if( loop )
{
CurrentWayPoint = 0;
}
else
{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
Now, this is the new waypoint;
var NewWayPoint = new GameObject("EnemyWayPoint3");