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 jeremy.schleining · Dec 08, 2013 at 05:55 AM · click objectsmousedown

Make OnMouse functions ignore GameObjects that pass in front of them

Hello,

I am presently attempting to make OnMouseExit() ignore objects that pass in front of the object clicked on. I have a GameObject in the scene that will respond to being hovered over and clicked on (essentially, this object is the ground). I also have other GameObjects in the scene moving around (bullets). The ground object has a script on it that detects whether the mouse is currently interacting with it:

 public class MouseTarget : MonoBehaviour
 {
     private bool hovering;
     private bool mouseDown;
     
     void Start ()
     {
         this.hovering = false;
         this.mouseDown = false;
     }
     
     void Update ()
     {
         //Debug.Log (this.mouseDown);
     }
     
     void OnMouseEnter()
     {
         this.hovering = true;
     }
     
     void OnMouseExit()
     {
         this.hovering = false;
         this.mouseDown = false;
     }
     
     void OnMouseDown()
     {
         this.mouseDown = true;
         
     }
     
     void OnMouseUpAsButton()
     {
         this.mouseDown = false;
     }
     
     public bool Hovering{get{return this.hovering;}}
     public bool MouseDown{get{return this.mouseDown;}}
 }

The problem comes when one of the bullets passes beneath the mouse while it is currently clicked on the target. When that happens, OnMouseExit fires off, turning off mouseDown.

How do I prevent this behaviour? I want the mouse to essentially ignore the bullets.

Thank you for any assistance!

-J-

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 Piesk · Feb 25, 2014 at 12:57 PM 0
Share

BU$$anonymous$$P, so many questions asking about this and not one of the threads are answered. I have to assume there is no answer and try something else =/.

I too am looking at a very similar problem, I need my On$$anonymous$$ouse functions to ignore a fog of war layer.

avatar image CodeElemental · Feb 25, 2014 at 01:14 PM 0
Share

You could create a layer for the specific group of objects and try raycast from camera for that specific layer. (efficiently ignoring the bullets obscuring the object). However i have no idea how you could detect when the hover leaves the object without raycasting every Update() call, which is kinda inefficient.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Commander5518 · Feb 25, 2014 at 02:36 PM

You could also not add a collider to it. On mouse functions will only work with a collider

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

19 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

Related Questions

How can i prevent a user from clicking morethan once on an instance of a gameobjectthat is busy spawning 1 Answer

GetMouse doesn`t work correctly 1 Answer

Can we click on any of the Gameobject 1 Answer

Image appear on click 0 Answers

Hide GUI Label when click in open space or on other objects 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