- Home /
How do I change textures at a click of a button
Hi basically I stumped I am trying to have a menu or layout that allows there to be an image (texture or icon) load within the window and text on another part explaining the image.
So button one shows image one and text for image one, button two shows image two and text for image two and so on.
For the most part I have worked around some of the layout issues (in around about way) but can't change the textures on the click of the button.
Please be gentle I am new (3 weeks) and I am a not a programmer so I am up to my chest in water at the moment. Ta
This is what I am using at the moment:
Screen.lockCursor = false;
GameObject.Find("FPC").GetComponent("MouseLook").enabled = false; GameObject.Find("FPC").GetComponent("Crosshair").enabled = false;
Time.timeScale = 0;
/ Button Content examples / var img1 : Texture2D; var img2 : Texture2D; var img3 : Texture2D; var img4 : Texture2D; var img5 : Texture2D; var img6 : Texture2D;
var windowRect : Rect = Rect (175, 150, 600, 600);
function OnGUI () {
windowRect = GUI.Window (0, windowRect, WindowFunction, "SCOTT'S BOOK:");
}
function WindowFunction (windowID : int) { // Draw any Controls inside the window here
if (GUI.Button (Rect (1,16,598,400), img1)) {
print ("you clicked the img");
}
if (GUI.Button (Rect (1,434,598,145), "ARTISTS NOTES:\n\n We are please to reveal to you a unique experiencing in online photographic exhibition.....\n\n Blah Blah checking code annd new line works", "button")) { print ("you clicked the icon"); }
if (GUI.Button (Rect (1,415, 100, 20), "img1", "button")) { print ("img1"); }
if (GUI.Button (Rect (99,415, 100, 20), "img2", "button")) { print ("img2"); }
if (GUI.Button (Rect (199 ,415, 100, 20), "img3", "button")) { print ("img3"); }
if (GUI.Button (Rect (299 ,415, 100, 20), "img4", "button")) { print ("img4"); }
if (GUI.Button (Rect (399 ,415, 100, 20), "img5", "button")) { print ("img5"); }
if (GUI.Button (Rect (499 ,415, 100, 20), "img6", "button")) { print ("img6"); }
if (GUI.Button (Rect (1,579, 597, 20), "Close", "button")) { print ("you closed the window");
Destroy (this);
Time.timeScale = 1;
GameObject.Find("FPC").GetComponent("MouseLook").enabled = true; GameObject.Find("FPC").GetComponent("Crosshair").enabled = true;
gameObject.AddComponent ("LockCursorNew");
Screen.lockCursor = true;
}
}
@Scott, You probably noticed that the whole code of your post looks kinda weird.. right?
Answer by Kitty · Mar 09, 2010 at 05:31 PM
I'm still a bit of a noob to scripting, but hopefully this should help you to get your click texture change. If nothing else, get you started.
var normalTexture : Texture 2D; var rollOverTexture : Texture 2D;
function OnMouseEnter(){guiTexture.texture = rollOverTexture;}
function OnMouseExit(){guiTexture.texture = normalTexture;}
As for what you have above for your buttons, you might want to look into GUILayout scripts. Unity's site has a great script reference and it's come in handy many times.
Answer by lowbloodsugar · Mar 07, 2010 at 05:11 AM
If you are not a programmer you should first learn how to code before getting yourself into a position where you need to code to solve a problem.
There are many books, websites, and schools that teach programming. Some even teach programming with an emphasis on game design. Start there young Jedi. Be patient and the your path will become clear.
If you can't do that that you should consider hiring a programmer to help you.
What kind of answer is that? You gotta start somewhere... might as well just jump at it! :)
that guy must be a programmer with no job because graphic designers now lear to do scripting by ourself.. yeah!
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
How to make a half 2d- half 3d main menu?? 1 Answer
Unity Main Menu 1 Answer
How to place/add a HD image/picture in background of my game? 0 Answers
What does a quad look like? 1 Answer