I have a button. I want it to switch textures when its clicked and return to normal when let go. Its a GUI Texture. Right now both "Up" and "Down" versions of the texture are in my project folder and not attached to any object. In the Inspector both texture types are set to "GUI".
The primary issue Im having it getting my variables to call for the textures and getting my IF statement to do the swap. This is what I have:
var btnSoldier_Up = GUI_Soldier_Up.Texture(109,96);
var btnSoldier_Down = GUI_Soldier_Down.Texture(109,96);
function OnGUI() {
if (GUI.Button (Rect(0,0,109,96),btnSoldier_Up))
renderer.material.mainTexture = btnSoldier_Down;
}
According to the help document linked below, it looks like this should work. But it's not. Any suggestions?
http://unity3d.com/support/documentation/ScriptReference/Texture2D.Texture2D.html
http://unity3d.com/support/documentation/Components/class-Texture2D.html
Unfortunately most of the help areas I found on searching were for C#, Im programming in Javascript so it's been a bit confusing for me. Thanks in advance!