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 17, 2013 at 10:31 PM · guifunction

function GUI.DrawTexture with OnMouseEnter/Exit to change texture all within script?

Basically, I want to make a title screen all within a script so that I can set a variable to turn off the GUI and go straight into the game without loading another level. Basically an intro all within the title screen.

When I draw the GUI, and when the mouse enters currentTexture, it will set the value to the variable of controlStartEnteredTexture. If I want to save space and do it in all one script, then would I make variables for each element, and then make more functions for OnMouseEnter and OnMouseExit, or can I say it both statements, but start a new line and code there? Here's what I got and I'll tell you if it worked after I code it.

 // These are the place holder variables that hold the start texture, and will change upon mouse enter/exit.
 var currentStartGameTexture : Texture2D;
 var currentExitGameTexture : Texture2D;
 // These variables define what the textures should change into.
 var hoverStartGameTexture : Texture2D;
 var hoverExitGameTexture : Texture2D;
 // These variables define what the current textures will change into when you aren't hovering over it.
 var standStartGameTexture : Texture2D;
 var standExitGameTexture : Texture2D;
 // This texture is what makes the background.
 var backgroundTexture : Texture2D;
 
 function OnGUI(){
     // This draws the background centered and scaled to be on any resolution.
     GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), backgroundTexture, 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), currentStartGameTexture, ScaleMode.ScaleToFit, true, 0);
     // 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), currentExitGameTexture, ScaleMode.ScaleToFit, true, 0);
 }
 // OnMouseEnter will change the current texture to the hover texture based on what it is being hovered over.
 function OnMouseEnter(){
     // This is the start game icon that will change when the mouse is hovered over it.
     currentStartGameTexture = hoverStartGameTexture;
     // This is the exit game icon that will change when the mouse is hovered over it.
     currentExitGameTexture = hoverExitGameTexture;
 }
 // OnMouseExit will change the current texture to the stand texture.
 function OnMouseExit(){
     // This is the start game icon that will change the current texture to the stand texture.
     currentStartGameTexture = standStartGameTexture;
     // This is the exit game icon that will change the current texture to the stand texture.
     currentExitGameTexture = standExitGameTexture;
 }

Nothing happens in game, so I assume that didn't work, so now I am going to see if it will change if I only render only a single GUI at once with one script and see if it changes. I will post that script below.

 function OnGUI(){
     // 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), currentStartGameTexture, ScaleMode.ScaleToFit, true, 0);
 }
 // OnMouseEnter will change the current texture to the hover texture based on what it is being hovered over.
 function OnMouseEnter(){
     // This is the start game icon that will change when the mouse is hovered over it.
     currentStartGameTexture = hoverStartGameTexture;
 }
 // OnMouseExit will change the current texture to the stand texture.
 function OnMouseExit(){
     // This is the start game icon that will change the current texture to the stand texture.
     currentStartGameTexture = standStartGameTexture;
 }


That doesn't work either. I don't think OnMouseEnter/Exit is referring to the image at all, which is why it's not working. It's just stating that OnMouseEnter... blablabla.

A fully coded GUI that I am able to change the textures when the mouse hovers over that GUI element is a lot harder than I thought.

Another issue is that if I add a boolean statement before a the function OnGUI, it will give me several errors. Am I not allowed to put anything before a function? Just so you know, I'm new to scripting and I'm self learning, so it might be a stupid question.

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

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

How do I create a GUI on collision detection? 1 Answer

GUI.Window function with variables? 3 Answers

Display GUI when function is called 2 Answers

Button is unable to grab functions with two parameters? 0 Answers

Variable won't change, any suggestions? 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