Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mrapple · Nov 03, 2011 at 03:20 AM · guitexturemousetexture2dhover

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Nov 03, 2011 at 03:28 AM 0
Share

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.

avatar image mrapple · Nov 03, 2011 at 03:32 AM 0
Share

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.

avatar image syclamoth · Nov 03, 2011 at 03:49 AM 0
Share

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).

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by natestale · May 01, 2014 at 08:52 PM

I dont know if this is useful (2014) but, if i reach this place looking for the same question, im sure that it is going to help another people, so here i go, this is the solution for HOVER and CLICK using UnityScript (Javascript). Hope i can help anyone ;)

 var normalTex : Texture2D;
 var hoverTex : Texture2D;
  
 function OnMouseEnter () {
  guiTexture.texture = hoverTex;
 }
  
 function OnMouseExit(){
  guiTexture.texture = normalTex;
 }
  
 function OnMouseDown(){
  Debug.Log("clicked");
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mrapple · Nov 03, 2011 at 05:37 AM

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");
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to check if player is hovering mouse over a GUI Box 3 Answers

How to make a Hover event on GUI.Button 6 Answers

Detecting Mouse Over Using Tooltip 2 Answers

How to script GUI Texture Window to see it in Script (Object's component) 1 Answer

Specify OnMouseEnter 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges