- Home /
Why Stop everything but monsters not stop In Pause Menu
Why not stop In pause manu ?
When I press "ESC"
Stop everything but monsters not stop
why Monster not stop?
Please help me.
This Vdo In my game:
http://www.youtube.com/watch?v=J4tkubYTdVo
Code Monster
var speed:float= -0.01;
var x:int=1;
function Start () {
transform.localScale.x=x;
}
function Update () {
transform.position.x+=speed;
}
function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="wallban")
{
x=x*-1;
transform.localScale.x= x;
speed=speed*-1;
}
}
Code Pause
#pragma strict
public static var pausemenu = false;
function Start () {
pausemenu = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
}
function Update () {
if(Input.GetKeyDown("escape")){
if(pausemenu == true){
transform.position.x= 3.263623;
pausemenu = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
}
else if(pausemenu == false){
transform.position.x= 0.0406395;
pausemenu = true;
AudioListener.volume = 0;
Time.timeScale = 0;
Screen.showCursor = true;
}
}
}
[1]: http://www.youtube.com/watch?v=J4tkubYTdVo
Answer by Crazydadz · May 09, 2013 at 12:29 PM
In your update function of your monster you are not using Time.deltaTime: transform.position += speed * Time.deltaTime. Use Time.deltaTime to have a constant speed depending on the game framerate. Without it, your motion will not be smooth if the framerate is not constant. When you set Time.timeScale to 0, it will set Time.deltaTime to 0 so the speed multiply by 0 will be 0, so the motion will stop.
http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613101902im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Pause Menu issue with mouse 1 Answer
Dragging Unity Editor will pause running game? 0 Answers
How can I insert Load Level in this Script? 1 Answer
Pause between user mouse clicks 1 Answer
Make game pause on world enter 1 Answer