- Home /
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.??
Answer by Ashkan_gc · Apr 30, 2011 at 05:01 AM
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;
}
Cheers dude, such a simple answer in the end, i though this question had been long forgotten
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 }
Answer by Borgo · Jan 13, 2011 at 12:17 PM
Simple way:
Make a empty object with only GUIs, transform in a prefab, destroy to "hide" and instantiate to "show".
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.
Answer by cormac · May 05, 2011 at 11:03 AM
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) {
Your answer
Follow this Question
Related Questions
How Do I Center A GUI Label? 5 Answers
OnMouseOver Tower Gui Health Bar 2 Answers
how to get Gui in OnGUI function to resize with the window? 1 Answer
Make a document pop up on screen 1 Answer