- Home /
activating a box using a GUI button
Hey :) i was wondering if this can be done, i want it so that when i hit a GUI button a box will activate, basically the box will have a map texture on it so it looks like when you hit the GUI button the box will appear with the map on it, if anybody could help me it would be most appreciated, or that could point me in the right direction :)
Thanks
Answer by DaveA · Mar 01, 2012 at 01:00 AM
Assuming you mean a 3D box (or any 3d object): (not tested)
var myBox; // assign this in the Inspector (or in Start routine with a Find, or similar)
function Start()
{
myBox.renderer.enabled = false; // hide it
}
function OnGUI()
{
if (GUI.Button (Rect (10, 10, 100, 20), "Hit me"))
myBox.renderer.enabled = true;
}
If you mean GUI Texture (2D HUD):
(not tested)
var showBox = false;
var aTexture; // set in Inspector to be your map texture
function OnGUI()
{
if (GUI.Button (Rect (10, 10, 100, 20), "Hit me"))
showBox = true;
if (showBox)
GUI.DrawTexture(Rect(10,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0f);
}
The top one was what i wanted thank you :) massive help
Your answer
Follow this Question
Related Questions
Exiting witha GUI Button 1 Answer
Delaying GUITexture!!! 3 Answers
How can I make a gui with buttons pop up in javasript? 1 Answer
Is there anyway to only show a part of a GUI image during the game? (C#) 1 Answer
Simple GUI Question 1 Answer