x


GUI.Button Texture Swap?

Is there an way to use the on press functionality of a GUI.Button to change the texture assigned to it. Something to the effect of,

public Texture2D Texture1
public Texutre2D Texture2

void OnGUI() {


    if (GUI.Button (new Rect (50,410,60,60),  Texture1)) {
                //Swap to Texture2
            }
more ▼

asked Aug 11 '10 at 08:12 PM

Brian 5 gravatar image

Brian 5
5 2 2 3

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

1 answer: sort voted first

first make a main texture "textureButton" then assign that texture " Texture1" in the awake function. Use the 3rd texture "Texture2" when you want to swap it

var Texture1 : Texture; var Texutre2 : Texture; var TextureButton: Texture;

function Awake() { TextureButton = Texture1; }

void OnGUI() {

if (GUI.Button (new Rect (50,410,60,60),  TextureButton)) {
         TextureButton = Texture2;   //Swap to Texture2
        }
more ▼

answered Aug 11 '10 at 08:19 PM

ThumbStorm gravatar image

ThumbStorm
418 27 33 42

(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:

x3675
x2193
x786
x51

asked: Aug 11 '10 at 08:12 PM

Seen: 2858 times

Last Updated: Aug 11 '10 at 08:12 PM