- Home /
Pausing a gameObject that has movement in and Update()?
Excellent
You didn't provide any code of how you handle movement in your Update() call, this really depends on how you code it inside your Update() (speed * Time.deltaTime or Coroutine ?) and what did you use (Rigidbody or transform ?)
You need to tell us more about it so we can help.
Answer by tormentoarmagedoom · Apr 04, 2018 at 09:25 AM
Good day.
If ypu are moving the object inside the update, and you have a bool variable to know if user pressed pause, ypu just need to allow enter inside the movement functions when pause is not actice. If you also need to stop the time, do the same.
Inside the update create a
if(!pauseSwitch)
{
Timer functions...
Moving functions....
}
Answer by Harinezumi · Apr 04, 2018 at 09:46 AM
You are moving using the variable speed
, which I assume is not updated when Time.timeScale
is set to 0. Instead use Time.deltaTime
(which is premultiplied by Time.timeScale
), and multiply it by speed
to have control over how fast it moves. Something like this:
private void Update () {
timer += Time.deltaTime * speed;
// this is the same you have, I just condensed it into one line
transform.Translate(Mathf.Cos(timer) * width, Mathf.Sin(timer) * height, 0);
}
Follow this Question
Related Questions
Pause a script without pausing the whole game 2 Answers
Coroutines, WaitForSeconds with function Update? 3 Answers
Main Menu in different scene - pause game 3 Answers
Pause at end of game 2 Answers
Pause Menu problem 0 Answers