|
Hello everyone! I've made a script, witch checks if the touchpad is touched and stops time, setting the variable paused = true, hiding the HUD(including the touchpad) and displaying the GUI.Button. The problem is: after the touchpad(named lePauseButton) is touched IT DOESN'T DISPLAY THE BUTTON. Here's the script: That's pretty much it, I've spent over 5 hours on studying the sctipt, raped the google for answer but i couldn't find a thing. Help will be much appreciated. Take Care!
(comments are locked)
|
|
The reasons for OnGUI not be called are : 1) the function's name is incorrect (not your case). 2) The gameObject is inactive. 3) The component is disabled. I doubt that your problems is in those three cases. FIRST IDEA : A timeScale null won't stop the GUI call, that would be unfortunate for a pause menu. So the problem comes from the boolean "paused". I don't think you ever get the print "Paused", which means the input is incorrect. I don't code on mobiles so I can't help, but I'm sure there is a lot of informations about it. SECOND IDEA : The pause works, the GUI button is drawn, however the texture is incorrect. Missing, too big, doesn't fit, you name it. Try with a string first. The button style should be visible however, so this seems unlikely. Thank you for the answer but everything you described above won't help. As you doubted, those 3 reasons aren't the problem. I get the print("pause") and I checked if the GUI button is correctly positioned and scaled. Unfortunately the problem still remains.
Jun 12 '12 at 05:47 PM
Phil25
I tried that code (replaced the touch by getkey) and it does work. The error must come from elsewhere. var paused : boolean = false;
var resumeButton : Texture2D;
function Update () {
if ( Input.GetKeyUp(KeyCode.Space) && !paused)
{
print("Paused");
Time.timeScale = 0.0;
paused = true;
}
}
function OnGUI ()
{
if(paused)
{
if(GUI.Button (Rect (Screen.width/2 - 100, Screen.height/2 - 200, 200, 100), resumeButton))
{
print ("Unpaused");
Time.timeScale = 1.0;
paused = false;
}
}
}
Jun 12 '12 at 07:17 PM
Berenger
Thank you Berenger, I see what the problem is.. Damn.. when i was setting pauseButton.active=false when paused=true, I realized that the resumeButton GUI that I wanted to show up then was attached as a child to pauseButton, and it was disappearing with it. Thank all of you for your help, I wouldn't think of it...
Jun 12 '12 at 09:06 PM
Phil25
(comments are locked)
|

if you put a
print("test");or something similar as the first command in thefunction OnGUI () {block .. does it print?Actually .. I wonder if it's something as crazy as you setting the
Time.timeScale = 0.0;causing both theUpdate()andOnGUI()functions to never be called again .. because the time is stopped? ..Enter .. the Twilight Zone.... Crazy idea. xD (edit: combined two comments into one)It will work, but it's going to slow down your computer. print is hell of a function.
@Berenger - the
print()function I asked for was just for debugging to see if the OnGUI() function was even being called. :P If it is, then move the print() down into theif()block nested within, and of course .. continue as necessary. That's how I'd debug this, anyway. :\Then disappear I shall.
@Berenger - Strange that the image you posted has been making huge appearances all over 4chan .. and you post it .. Coincidence or conspiracy!? I think
NOT!