- Home /
Setting GUI textures
Hi all.
How do you define the texture or picture name in the editor? For example, If I have a texture named "Gun", how can I say that when I press "A" I want the texture inside the OnGUI() function to be changed to "Gun" texture, when pressed "B" the texture is changed to "Rifle" etc..
I know how to do the array with multiple textures already assigned, and then swapping them, but that's not what I need.
Thanks.
Answer by crazyKnight · Nov 30, 2011 at 12:04 PM
i dont know what you are exactly asking for but as per my understanding of the question hope this code helps
var Gun : Texture2D;
var Rifle : Texture2D;
private var Temp : Texture2D;
function Start ()
{
Temp = Gun;
}
function OnGUI()
{
GUI.Label(Rect(5,5,64,96),Temp);
if(GUI.Button(Rect(20,100,30,20),"A"))
Temp = Gun;
if(GUI.Button(Rect(50,100,30,20),"B"))
Temp = Rifle;
}
I meant something like when you import the texture in the editor, it's shown in the list. I meant, some possible way of reading it from the script. For example, read the texture gun.png and assign it into Temp. But this works also good. I guess I can live with this. Thanks for helping :)