|
I'm trying to get a script going that will perform different functions based off of the buttons you press. The eventual end result will be; when you click on a door to go to the next scene, it will pop up a box confirming that you'd like to go. If you click yes, It will Load the next level, if you click no, it will simply turn the GUI back off until you click the door again. I'm trying it out on a box (it should yield the same results in the end game) If you click "yes", it destroys the box... that part works... however, I can't figure out what to do to make "no" turn the GUI off.
Any Ideas? Thanks much!
(comments are locked)
|
|
Put " To re-enable, use
This way you don't need extra logic, and the OnGUI function only runs when needed, not all the time. That solved that problem, Thanks. Now I just need to figure out how to activate the GUI when I click on the object. It was working before, but now, not so much... Thanks! =)
Apr 25 '10 at 01:07 AM
CalledToGaming
@CalledToGaming, once you disable the GameObject (with this answer), it won't respond to mouseclicks any more, which is why it's not working.
Apr 25 '10 at 01:31 AM
Cyclops
@CalledToGaming: See my edit...just set enabled = true.
Apr 25 '10 at 01:51 AM
Eric5h5
@Cyclops: That's incorrect...OnMouseDown, etc., will still respond when a script is disabled. Setting enabled = false doesn't disable the entire game object (you need gameObject.active = false for that), it only disables the script.
Apr 25 '10 at 01:56 AM
Eric5h5
@Eric5h5, really? Hm, I wasn't clear what the enabled = false was referring to, I figured it was the GameObject, not the attached script. So - when the script is disabled, it still responds to mouse clicks? Seems odd to me - not sure what enabled does then. But, I stand corrected...
Apr 25 '10 at 01:59 AM
Cyclops
(comments are locked)
|
|
I think what you want is, to not display anything until a box/door is clicked (rather than disabling the GameObject entirely). Consider re-writing it like this: Yeah, Basically, I'm trying to be able to click on the object (door or in this sample case, a box) and make the GUI pop up when I click the object. When I click "No" I want the GUI to disappear, but I want to be able to recall that GUI if i click on the object again. In the case that it's to load a level, if I decide to wait, I want the GUI to be able to pop back up again when I come back to the door.
Apr 25 '10 at 01:30 AM
CalledToGaming
@CalledToGaming, this should do it - assuming you got the last version :) I just changed it to have OnMouseUp().
Apr 25 '10 at 01:33 AM
Cyclops
Eureka! You're a godsend. Thanks much! It works Exactly as I hoped it would.
Apr 25 '10 at 01:36 AM
CalledToGaming
(comments are locked)
|
|
Create a gameobject and insert your OnGUI() inside of it after some GUI buttons clicked just destroy the game object.
(comments are locked)
|
