x


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;





    }

}

more ▼

asked Mar 05 '10 at 11:54 PM

Scott 2 gravatar image

Scott 2
42 4 4 6

@Scott, You probably noticed that the whole code of your post looks kinda weird.. right?

Mar 06 '10 at 03:08 AM Lipis
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 09 '10 at 05:31 PM

Kitty gravatar image

Kitty
79 7 7 17

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 07 '10 at 05:11 AM

lowbloodsugar gravatar image

lowbloodsugar
433 9 11 16

What kind of answer is that? You gotta start somewhere... might as well just jump at it! :)

Feb 02 '11 at 09:35 AM GearWorker

that guy must be a programmer with no job because graphic designers now lear to do scripting by ourself.. yeah!

Dec 27 '11 at 03:14 AM qinghill
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2200
x386
x56

asked: Mar 05 '10 at 11:54 PM

Seen: 7718 times

Last Updated: Dec 27 '11 at 03:14 AM