Hello! I'm trying to make an enemy retreat after so many seconds after it's spawned. I tested out the transform.position and the enemy moves straight towards, so I know that part works. However, when I tried to make the time delay happen by using invoke() code and putting the transform code in a custom function, the enemy remains where it was spawned.
#pragma strict
public var enemyspeed : float; //how fast enemy goes
private var retreatPoint: Vector3; //holds the coordinates to the retreat point
private var step : float; //speed *frames value
function Awake () {
// sets speed of enemy
var step = enemyspeed * Time.deltaTime;
}
function Start () {
//after 4 seconds, bunyip retreats
Invoke ("BunyipRetreat", 4);
}
function Update () {
//coordinates for retreatingpoint
retreatPoint = Vector3(24,0,20);
}
//custom function
function BunyipRetreat() {
//moves bunyip to retreating point
transform.position = Vector3.MoveTowards(transform.position,retreatPoint,step);
}
↧