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
1
Question by masterlcm · Mar 07, 2014 at 07:26 AM · objectmousemouseovermouseeventmouseenter

How to detect Mouse Events when the object is coverd by another object?

For example, I have put Sphere B on Cube A.

alt text

Then I add a script to Cube A, where the script is used for detecting onMouseOver and onMouseExit.


 bool     isMouseEntered  = false;
 void OnMouseOver ()
 {
         Debug.Log ("Enter");
         isMouseEntered = true;
 }
 void OnMouseExit ()
 {
         Debug.Log ("Exit");
         isMouseEntered = false;
 }



However, when I play the scene and move mouse around, I cannot get an OnMouseOver event but an OnMouseExit event when mouse is pointing over Sphere B.

What can I do so that I can receive OnMouseOver event even if there were many game objects covered my Cube A?

Comment
Add comment · Show 1
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 OSG · Mar 07, 2014 at 07:46 AM 0
Share

According to my knowledges, u should use Layers. But I know the only way to do this with Physics.RayCast(). In this case you have to implement On$$anonymous$$ouseOver() by yourself. If it fits you I can help with code. Hope somebody has better way.

1 Reply

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

Answer by Jiro-Ng · Mar 07, 2014 at 07:51 AM

Two way to solve this.

First, you set the Sphere layer to IgnoreRayCast. With this, the MouseOver function will ignore the sphere object. This method is simple but you will not able to use MouseOver on the sphere anymore.

Another way is using Physics.RaycastAll instead of MouseOver.

 void Update () 
     {
         RaycastHit[] allHit = Physics.RaycastAll(Camera.main.ScreenPointToRay(Input.mousePosition));
         foreach(RaycastHit hit in allHit)
         {
             if(hit.collider.gameObject.name == "Cube A")
             {
                 //do something here
                 break;
             }
         }
     }
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 masterlcm · Mar 07, 2014 at 08:37 AM 0
Share

Great! It works. Thanks.

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

22 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

Related Questions

"E" to grab an object... 3 Answers

How to make object clickable when user enter collider ? 0 Answers

I need to be able to detect the mouse pointer entering a trigger area *through* an object that I'm dragging. 0 Answers

Changing a material with a mouse click 2 Answers

MouseOver different Objects C# 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