x


Pause button

I am trying to make a button (LeftAlt) that will set the timeScale to 0 and show/unlock the cursor but my script isn't working, here is my script (JavaScript):

var p = 0;
function Update () {
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 0)
{
Time.timeScale=0;
Screen.showCursor = true;
Screen.lockCursor = false;
p = 1;
}
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 1)
{
Time.timeScale=1.0;
p=0;
}

}
more ▼

asked Mar 20 '12 at 01:23 AM

alpheus125 gravatar image

alpheus125
0 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
p = 1;
}
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 1)

That's going to set p to 1 then check that p == 1

var p = 0;
function Update () {
if (Input.GetKeyDown(KeyCode.LeftAlt))
{
  if (p == 0)
  {
   Time.timeScale=0;
   Screen.showCursor = true;
   Screen.lockCursor = false;
   p = 1;
  }
  else
  {
   Time.timeScale=1.0;
   p=0;
  }

}
more ▼

answered Mar 20 '12 at 01:25 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left

EditorApplication.isPlaying = false;

more ▼

answered Sep 13 '12 at 01:06 PM

vahidsahrabin gravatar image

vahidsahrabin
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x572
x261
x83
x6

asked: Mar 20 '12 at 01:23 AM

Seen: 774 times

Last Updated: Sep 13 '12 at 01:06 PM