Stopping a MoveTowards
I'm using Vector3.MoveTowards to move a gameobject from A to B.
When the user pauses the game though, I want the gameobject to stop moving.
How can I force the moving gameobject to stop if pause == true ?
Posting your code containing the function would help people answer your question.
The code is just 'transform.position = Vector3.$$anonymous$$oveTowards (transform.position, target.position, 1)'. That moves it, I just don't know how to force it to stop before it reaches end
Just stop calling it.
if (!pause)
{
// do stuff when you're not paused
}
ahh, I got confused. I thought when you call the code it moves to that location until it reaches it, didn't realize it had to be done each loop. Thanks
Answer by ThomasVandenberghe · Jan 29, 2016 at 04:00 PM
if (!paused)
{
transform.position = Vector3.MoveTowards (transform.position, target.position, 1);
}
Now only when the game is not paused the code will be executed.
Answer by $$anonymous$$ · Jan 31, 2016 at 02:46 PM
you might want to use this bit of code
Time.timeScale = 0;
Answer by ata_2 · Jan 31, 2016 at 02:47 PM
i think simple way to do it is to when you try to pause game use this code Time.timeScale = 0f; and when want to resume game use this code Time.timeScale = 1f; try this if you get any problem with this you can put your code in one if to check if pause menu showed like active don't run this code
Your answer
Follow this Question
Related Questions
GameObject not looking at me.. 1 Answer
How to restrict object's movement to a bezier curve? 0 Answers
How can I stop a gameobject movement with timer? 0 Answers
Mesh Movement 0 Answers