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 hijinxbassist · Mar 27, 2012 at 06:00 AM · guionmousedownonmouseenteronmouseuponmouseexit

OnMouseDown

Im trying to get a print out of OnMouseUp/Down, OnMouseEnter/Exit none are printing anything... Am i suppose to do something special for these functions to work? I have the functions on all the GUI scripts in the game, i click hover over and whatever else i can think of, yet not a single print. The Objects who have the GUI scripts attached do no belong to Ignore Raycast Layer...I randomly got 1 print(after restarting Unity) when i started the game, no click in the editor. Im lost on this one.

On my main GUI script..

 function OnMouseDown()
 {
     overGUI=true;
     print("Down");
 }

On a different GUI script

 function OnMouseEnter()
 {
     overGUI=true;
     print("Enter");
 }
Comment
Add comment · Show 2
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 AlucardJay · Mar 27, 2012 at 06:06 AM 0
Share

does the object this script is attached to have a collider ? sry , cannot help with GUI Elements

avatar image hijinxbassist · Mar 27, 2012 at 06:11 AM 0
Share

No they do not. Im trying to get it to work for GUI Elements Only. The ref says either GUIElement or Collider. Its wierd bcuz its not like its not GUI enough...i have a Window with a button in it, labels all over the place, pics rendering all over the screen. Ugh, maybe time for a comp restart...

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Mar 27, 2012 at 11:04 AM

Don't confuse GUIElement (GUIText, GUITexture) components with UnityGUI (OnGUI callback, GUI class, GUILayout class) these are two different things. OnMouseDown / Up / Enter / Exit works only for GameObjects with a GUIElement component attached. Those callbacks aren't called for GUI controls created in OnGUI().

Comment
Add comment · Show 2 · 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 hijinxbassist · Mar 27, 2012 at 02:23 PM 0
Share

Wow, i misinterpreted that completely. Thanks for the clarification. Guess i gotta figure out a new way to detect the mouse click over rendering screen gui. Now that ive had a day to think about it, it shouldnt be to bad. Thanks again.

avatar image Bunny83 · Mar 28, 2012 at 03:51 PM 1
Share

Since all HUI controls are Rects you could use Rect.Contains to test if the mouse is over a certain control (or screen space ;) ).

avatar image
0

Answer by zerox911 · Mar 27, 2012 at 09:04 AM

try something like this ...

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

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

7 People are following this question.

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

Related Questions

OnMouseOver Problem 3 Answers

Multiple GUI textures one script 2 Answers

Text popup onMouseDown 2 Answers

Changing the Mouse's Range for OnMouse events 0 Answers

Change Font Style OnMouseEnter 0 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