x


Gui Texture Swap?

I made a menu for a small Unity game but I have a small something I would like to add, The problem is I don't know how to. Basically what I want to achieve is to have buttons on my score history page in the menu that will change the texture of the page itsself, this because we have 4 tracks (yes its a race game) and I don't want to have to make 4 score history levels. So is there someone who can help me to do this?

more ▼

asked Jun 03 '10 at 11:50 AM

Najrax gravatar image

Najrax
1 2 2 4

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

1 answer: sort voted first

The simple way to implement this is to create a public reference to a Texture2D and assign it the texture you want in the Inspector. From there when you want to change your texture you just have a reference to the GUITexture you want to swap textures of and assign the new texture using this:

myGUITexture.texture = myNewTexture2D;

Cheers,

==

more ▼

answered Jun 03 '10 at 02:04 PM

equalsequals gravatar image

equalsequals
4.5k 16 28 64

Great, I'll be sure to try it today, Btw do I need to change ''myNewTexture2D'' into the name of the particular texture? Since else how will unity know what texture to change in?

Thanks for helping this will make my menu look even better.

Jun 04 '10 at 05:08 AM Najrax

I am not really good at scripting so hoping you can help me with this one. Error: BCE0005: Unknown identifier: 'myGUITexture'.

Jun 04 '10 at 06:48 AM Najrax

"myGUITexture" is a variable you would create. Try adding the line public var myGUITexture:GUITexture in your javascript class and then through your Inspector assign the GUITexture you want to be able to swap.

Jun 04 '10 at 02:24 PM equalsequals
(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:

x5081
x3689
x2200
x475

asked: Jun 03 '10 at 11:50 AM

Seen: 3001 times

Last Updated: Jun 03 '10 at 02:50 PM