- Home /
Display GUITexture if statement is true.
Basicly what the title says. I need to show a GUI texture when a IF statement is true, if the statement is false, the GUI texture should be hidden. Example:
if ( electromilk == true )
{
//Show the GUITexture
}
How do i display the GUI texture only when the statement is true?
Answer by Eric5h5 · Oct 17, 2010 at 04:27 PM
guiTexture.enabled = true;
Okay, good. Now, that only works if the statement that is supposed to be true is in a script attached to the GUI texture, right? Is it possible to choose what GUI texture to show when the statement is true? Sorry for poor description in first post.
Answer by TSSTUDIOS · Jan 13, 2014 at 04:40 AM
assint publlic variables to diferent textures ill make this script for other textures ill post ina bit what im gonna make is
if pause guitexture pressed, hide play mode gui and show game object(pause menu)
private var hit : RaycastHit;
private var options : boolean = false;
public var optionsTexture : GUITexture;
public var pausemenuobj : Transform;
public var mobilebuttons : Transform;
function Start () {
}
function Update()
{
var touches = Input.touches;
//detect which mobile buttons are pressed and make decisions accordingly
for (var touch in touches)
{
if(touch.phase != TouchPhase.Canceled && touch.phase != TouchPhase.Ended)
{
if(optionsTexture.HitTest (touch.position))
// pausemenuobj.renderer.enabled = true;
pausemenuobj.active = true;
mobilebuttons.active = false;
}
}
if(Input.touchCount == 0)
{
}
else
{
//----------------------------------
}
}
function OnMouseDown () {
// pausemenuobj.renderer.enabled = true;
pausemenuobj.active = true;
mobilebuttons.active = false;
}
As u can see my mobilebuttons is a transform which means its a game objects not a gui texture, what i did was drag all my guitextures inside that game object, so when i disable the game object all the children will get disabled too, im choosing a game objects because i have been having problems with gui textures theere shoulçd be a layer system like in photoshop, anyway, this is one way u can go at it, there are many ways u can hide labels or u can cript what u wanan hide, or do it like me and select it on the inspector
aw btw this script is ready for mobiel touches and on mouse down do u can test the code one ur computer :)