x


Make GUI elements disappear

HI. I have a few GUI elements (two slider bars and a few buttons) onscreen which help me adjust the speed and position of a fly through camera, i am then recording the fly throughs with screen capture software. The problem is i would like the GUI elements to be invisible unless the mouse is over the screen. Can anybody help.??

more ▼

asked Jan 13 '11 at 11:56 AM

cormac gravatar image

cormac
11 4 4 5

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

3 answers: sort voted first

well! check the position of the mouse and depending it's position set a variable (say showGUI) to true and false and then in your OnGUI check the variable to see if you should draw the gui or not in this frame.

void OnGUI ()
{
if (showGUI == true) { //show your gui and call them }
else {//don't do anything related to those GUI elements }
}
void Update ()
{
if (Input.mousePosition.y > Screen.height/2 ) //check any other condition that is suitable for you
{
showGUI = true;
}
else
showGUI = false;
}
more ▼

answered Apr 30 '11 at 05:01 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

Cheers dude, such a simple answer in the end, i though this question had been long forgotten

May 05 '11 at 10:15 AM cormac

This is the final codde

function Update(){ if (Input.mousePosition.y < Screen.height && Input.mousePosition.y > 0 && Input.mousePosition.x < Screen.width && Input.mousePosition.x > 0) //check to see if the mouse is over the Screen { showGUI = true; } else { showGUI = false; }

function OnGUI(){ if (showGUI == true) { //gui stuff }

May 05 '11 at 10:59 AM cormac
(comments are locked)
10|3000 characters needed characters left

Simple way:

Make a empty object with only GUIs, transform in a prefab, destroy to "hide" and instantiate to "show".

more ▼

answered Jan 13 '11 at 12:17 PM

Borgo gravatar image

Borgo
998 9 13 25

I see what you mean, but i think to do this would mean hugh changes to my script, as the gui scripts are part of a much more complex script on the main camera which places it on a path defined by points in the scene and moves it along this path using iTween. all this script is on the main camera.

Jan 13 '11 at 12:48 PM cormac
(comments are locked)
10|3000 characters needed characters left

This is the code i used in the end

function Update(){

if (Input.mousePosition.y < Screen.height && Input.mousePosition.y > 0 && Input.mousePosition.x < Screen.width && Input.mousePosition.x > 0) //check to see if the mouse is over the Screen
{
showGUI = true;
}
else
{
showGUI = false;
}
function OnGUI(){

if (showGUI == true) {

more ▼

answered May 05 '11 at 11:03 AM

cormac gravatar image

cormac
11 4 4 5

(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:

x3689
x485
x49
x34

asked: Jan 13 '11 at 11:56 AM

Seen: 1419 times

Last Updated: Jan 13 '11 at 11:56 AM