Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by timedo · Jan 09, 2014 at 09:53 PM · eventonmouseoverclicks

onmouseover not work

Hello people! Im from Ukraine and i not good speak to Englesh(sorry).I have object consists of different parts, for example there is a mouse object that consists of a wheel, left click, right click, etc. I need that if I were brought to the example on the left mouse click in the console brought the "left click". Trying to each such object (left click, right ...) hang event, but it does not work, the message in the console is not displayed here is the script:

 using UnityEngine;
 using System.Collections;
  
 public class Example : MonoBehaviour {
     void OnMouseOver() {
         print("object name");
     }
 }
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

4 Replies

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

Answer by robertbu · Jan 09, 2014 at 09:56 PM

Your code is fine. Make sure 1) this script is attached to every object you want to report, 2) that every object has a collider, and 3) that the collider you click on is the front-most collider (i.e. there is no hidden collider between the mouse and your objects. You can replace your print() with:

 Debug.Log ("Name: "+gameObject.name);
Comment
Add comment · Show 1 · 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 timedo · Jan 10, 2014 at 12:02 PM 0
Share

thaks you!

avatar image
4

Answer by mihaa123 · Jun 12, 2016 at 02:19 PM

Not sure if you found what was wrong but for other people who had the same problem-

APPARENTLY, a rigidbody component on the parent of the object, without the object itself having a rigidbody is causing these functions not to work-

OnMouseOver(), OnMouseDown(), OnMouseEnter(), OnMouseExit() *maybe there are more, but these are the ones i tested.

I have NO idea why this is happening.

So the fix is either to attach a rigid body on the object on which you are calling the function above OR removing the rigid body component from the parent\parents of this object.

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 browne11 · Oct 22, 2016 at 09:41 PM 0
Share

Thanks bud, this was my issue.

It seems the documentation needs a bit of an update on this issue and the inspector does too.

avatar image moment_um · Jul 19, 2018 at 11:15 PM 0
Share

@mihaa123 This is actually the way ALL collision events happen in Unity. If you have 1 object with a rigidbody, and that object has children with colliders, all collisions report to the parent object with the rigidbody. In fact, if you use a RaycastHit, and access its transform, it will always return the object with the rigidbody that the collider belongs to. You have to specifically use the RaycastHit.collider to ensure you are accessing the correct collider.

avatar image
1

Answer by moment_um · Jul 19, 2018 at 11:04 PM

Your code is fine. Make sure:

  1. this script is attached to the object you're trying to use

  2. that the object has a collider

  3. Your object is not obstructed (it is the closest thing to the mouse, the event only gets called on the first thing the mouse touches, use Debug.Log ("over: "+ name) if not sure )

  4. it CAN NOT be a UI element (i.e. in the canvas with a rect transform)

also you are probably looking for OnMouseEnter or OnMouseDown as OnMouseOver gets called every frame.

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 salkony90 · Jan 12 at 02:45 PM

The thing I found out is that OnMouseOver only works in the Game tab and not working in the Scene tab :)

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Toggle Event passing bool [4.6+] 2 Answers

Unity 4.6 UI Event Trigger PointerUp when PointerDown was in other object 0 Answers

How can I detect a right-click on my UI button? 1 Answer

Get Global PointerEventData 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