Question by
ryannicholasbecker · Oct 19, 2020 at 09:34 AM ·
transform
How do I make an Enemy Sprite Change Direction after a Timer <= 0?
What I would like for this enemy sprite to do is to move side to side on the x axis until the player destroys said enemy. I have the timer and resetting it figured out but can't quite figure out how to change the directional movement once it does reach 0. I know I need a variable or a bool but all I've been able to do is make it drift in one direction or I get stuck with errors
Help would be appreciated
and the code that I have a the moment
{
public float speed = 3f;
public float resetTimer = 3f;
public float timer = 3f;
void Update (){
timer -= Time.deltaTime;
if (timer <= 0) {
Debug.Log ("turn");
timer = resetTimer;
}
transform.position += Vector3.right * speed * Time.deltaTime;
}
}
Comment
Your answer
Follow this Question
Related Questions
Make object move back and forth 2 Answers
NetworkTransform did not working with RegisterSpawnHandlers 2 Answers
2D topdown projectiles movement 0 Answers