I’m trying to find out how to get a clipboard to appear when I click a button. I have the clipboard texture as a GUI Texture, and it’s on the screen when the game is playing. How do I hide it until I press the button (which is one of the Unity default buttons), and then have it hide?
#pragma strict
// JavaScript
var icon : Texture2D;// Defines icon textures
var icon1 : Texture2D;// Defines icon textures
var icon2 : Texture2D;// Defines icon textures
var icon3 : Texture2D;// Defines icon textures
var icon4 : Texture2D;// Defines icon textures;
function OnGUI () {
GUI.Button (Rect (10,10,100,21), GUIContent ("Tools", icon, "Open tools"));// Makes Tools button
GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does
GUI.Button (Rect (115,10,100,21), GUIContent ("Chart", icon1, "View patient's chart"));//Makes Chart button
GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does
GUI.Button (Rect (220,10,100,21), GUIContent ("Interact", icon2, "Interact with patient"));
GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does
if (GUI.Button (Rect (10,700,120,21), GUIContent ("End Simulation", icon3, "Quit")))// Makes Quit button
Application.Quit();// Quits simulation if button is pressed
GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does
GUI.Button (Rect (325,10,100,21), GUIContent ("Help", icon4, "Get some help"));// Makes Help Button
GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does
}
I would want the button that says “Chart” to display the picture.
Do you have a bit of source code for us to help with? The short version is to add a boolean that is toggled when the user clicks a button. Then, when OnGUI iterates and sees that boolean is true, it will be render the clipboard texture.
– AndyMartin458Yeah. I put the buttons in their own scripts. Here's the one for the chart. #pragma strict var icon1 : Texture2D; function OnGUI () { GUI.Button (Rect (115,10,100,21), GUIContent ("Information", icon1, "View patient's chart"));//Makes Chart button GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does }
– hedge500if(GUI.Button (Rect (115,10,100,21), GUIContent ("Information", icon1, "View patient's chart"));//Makes Chart button){ showToolTip=true; } if(showToolTip){ GUI.Label (Rect (10,40,100,35), GUI.tooltip);// Shows description of what button does } And to hide in in the future you can start a coroutine witch would turn the showToolTip false, but this will render your button useless or at least you will only know what does it do when you already clicked it.
– gajdotThere's a compiler error saying that showToolTip is an unknown identifier.
– hedge500Yeah you need declare that :P if you are using csharp then private bool showToolTip = false; OR if Javascript: private var showToolTip : boolean = false;
– gajdot