- Home /
Question by
MrSausage1 · Nov 13, 2020 at 03:58 AM ·
movementcoroutinebeginnertime.deltatimecooldown
Moving a gameobject x time every x time
I have a gameobject and I want it to move down for 0.5 seconds every 1.5 seconds (something like a movement "cooldown"). I know I´m missing the 0.5s but I´m kinda new to Unity and I don´t know how to apply it. (As extra info the game is 2d) Hope I can get an answer :D
void Update()
{
_speed=0.0f
StartCoroutine(Move());
transform.Translate(Vector3.down * _speed * Time.deltaTime);
}
IEnumerator Move()
{
_speed = 2.0f;
yield return new WaitForSeconds(1.5f);
}
}
Comment
Answer by Revolution_Game · Nov 20, 2020 at 09:55 AM
bool stop = true;
float speed = 10f;
void Update()
{
if (stop)
{
StartCoroutine(Move());
}
}
IEnumerator Move()
{
Vector3 move = new Vector3(0, -2.0f, 0);
transform.position += move * speed * Time.deltaTime;
stop = false;
yield return new WaitForSeconds(0.5f);
stop = true;
}
I hope this can help you
Your answer
Follow this Question
Related Questions
Dash speed doesn't always APPEAR to increase when dash is in progress 0 Answers
How to move an object along the X and Z axis with arrow keys/wasd with javascript? 1 Answer
I cant seem to add a cooldown to this script 1 Answer
Waitforseconds causing erratice flickering between active/not active objects 0 Answers
Wait until movment animation ends 0 Answers