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 Prussian · Jul 16, 2013 at 11:17 PM · function

How to change GUI.DrawTexture with OnMouseEnter function?

So I'm self teaching myself, and this is the first kink along the way, and I was wondering what is the best way for me change the texture that made with GUI.DrawTexture by using OnMouseEnter and OnMouseExit so that I can change the texture to something else when the mouse is hovered over it, and then reset when it exits?

Normally, if I was doing this using the scene itself, I'd have no problem with it, but for something done entirely in a script, I'm really confused.

 // Allows you to disable to the gui when you want by setting this value to false.
 var guiDraw : boolean = true;
 // Allows you to set what texture you want the background to be.
 var controlBackgroundTexture : Texture2D;
 // Allows you to set what texture you want the start button to be when it is not entered in by the mouse.
 var controlStartNotEnteredTexture : Texture2D;
 // Allows you to set what texture you want the start button to be when it IS entered in by the mouse.
 var controlStartEnteredTexture : Texture2D;
 // Allows you to set what texture you want the exit game to be when it is not entered in by the mouse.
 var controlExitNotEnteredTexture : Texture2D;
 // Allows you to set what texture you want the exit game to be when it IS entered in by the mouse.
 var controlExitEnteredTexture : Texture2D;
 
 // Begins drawing the GUI.
 function OnGUI(){
     // Checks to see if the GUI is enabled, and if it is, it will display it.
     if(guiDraw == true){
         // This draws the background centered and scaled to be on any resolution.
         GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), controlBackgroundTexture, ScaleMode.ScaleToFit, false, 0);
         // This draws the start button to be centered on any resolution.
         GUI.DrawTexture(Rect(Screen.width/2.5, Screen.height/2.5, Screen.width/2, Screen.height/2), controlStartNotEnteredTexture, ScaleMode.ScaleToFit, true, 0) && {
             function OnMouseEnter(){
                 guiTexture.Texture = controlStartEnteredTexture;
             }
         }
         // This draws the exit button to be centered on any resolution.
         GUI.DrawTexture(Rect(Screen.width/2.5, Screen.height/1.6, Screen.width/2, Screen.height/2), controlExitNotEnteredTexture, ScaleMode.ScaleToFit, true, 0);
     }
 }

Now, if you tell me that I should just use OnMouseExit before GUI.DrawTexture, I'm seriously going to slam my head in my desk, because I might make this a little more difficult that what I am actually thinking of.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jamora · Jul 17, 2013 at 11:03 AM

OnMouseEnter and OnMouseExit should be separate functions. Unity will call them for you when appropriate.

What you should do is something like:

 var currentTexture : Texture2D;
 
 function OnGUI(){
 
     GUI.DrawTexture(Rect(/*values*/),currentTexture)
 }
 
 function OnMouseEnter(){
     currentTexture = controlStartEnteredTexture;
 }
 
 function OnMouseExit(){
     currentTexture = controlExitNotEnteredTexture;
 }
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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Finding the angle between two GameObjects 1 Answer

return value of a function passed to another function as a parameter 0 Answers

Function that triggers something as soon as Object is "Set Active" 3 Answers

what code should i be using if im only wanting a function to happen if a raycast does not return a hit 1 Answer

Spaceship game, Pick weapon 1 Answer


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