x


GUI texture to change texture when hovered over or clicked?

Trying to get a script working for GUI where's the GUI texture will change when I've hover'd over it etc, just wondering how'd I'd go about doing that?

Not to sure if I'd use OnGUI() or OnMouseEnter etc.

I'm using C# Thanks if you can help!

more ▼

asked Nov 03 '11 at 03:20 AM

mrapple gravatar image

mrapple
31 11 13 15

Depends. How does your current GUI work? There are ways of making this happen for any method, really, but I'd like to know your specifics before I can tell you one of them. If it's just UnityGUI (as goes inside of OnGUI) I'd use a custom GUIStyle which had a different texture for 'hover' in the background.

Nov 03 '11 at 03:28 AM syclamoth

At the moment, I don't have anything for the GUI. I have a image without a blur at the back and one that makes it shine for when it is hovered, I just don't know the script on how to change textures.

Nov 03 '11 at 03:32 AM mrapple

Well, just use OnGUI for that stuff. All the functionality is pretty much there for you already! It's not a script exactly, you define a custom GUIStyle in your script at the top, like

public GUIStyle buttonStyle;

then set it all up in the inspector (including dragging images in from the Project window).

Nov 03 '11 at 03:49 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Update;

This is what I'm using to test, I've got some other scripts setup etc, but thats irrelevant, what I want to know is how to change a texture to another texture when the mouse is over it.

This is what I tried, which gives no errors but doesn't work.

public Texture2D hoverTexture;
public Texture2D NormalTexture;
public Texture2D PressTexture;

void OnMouseEnter()
{
    NormalTexture = hoverTexture;
    print("EnteredArea");
}
more ▼

answered Nov 03 '11 at 05:37 AM

mrapple gravatar image

mrapple
31 11 13 15

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

x3698
x2210
x986
x355
x55

asked: Nov 03 '11 at 03:20 AM

Seen: 2407 times

Last Updated: Nov 03 '11 at 05:37 AM