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 avidesk · Oct 20, 2011 at 07:29 PM · mouseclickdetect

Mouse Click not detected

I have a script that has an OnMouseDown function, and toggles a boolean value. The object I want the script attached to is a child object, 2 or 3 levels deep in my main parent game object. If I attach the script to that main parent object or any of its children, it doesn't do anything. If I attach the script to any other object in my scene, it works as expected. All of the objects I try to use have a box collider component.

Is there any reason why this would be happening?

Comment
Add comment · Show 5
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 jahroy · Oct 20, 2011 at 09:10 PM 0
Share

Sorry to ask, but is the parent object enabled?

avatar image avidesk · Oct 20, 2011 at 10:50 PM 0
Share

of course :)

avatar image CarlLawl · Oct 21, 2011 at 01:45 PM 0
Share

paste the code and ill take a look

avatar image avidesk · Oct 21, 2011 at 08:38 PM 0
Share

The code isn't the problem unfortunately. It's as simple as it gets, and works on any object I test it on, except my main object (a vehicle), or any of its child components.

private bool _active; void On$$anonymous$$ouseDown () { _active = !_active; }

(Don't know why my code is formatted like that, the line breaks are normal in the textbox I'm typing in)

avatar image jahroy · Oct 21, 2011 at 09:08 PM 0
Share

You have to type it in an answer box, then format, then paste into a comment box to get it formatted right.

Wish I could help you with your question!

Is it due to a variable na$$anonymous$$g issue? Can't help but asking after seeing a variable named _active....

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jahroy · Oct 21, 2011 at 09:17 PM

This might be stupid, but is there a chance that OnMouseDown could be getting called multiple times or getting called from OnGUI by the object in question?

I've had trouble in the past using someBoolean = ! someBoolean when certain functions return true multiple times.

For example, I first tried to use this when impementing keyboard shortcuts with Input.GetKey and determined that I had to use Input.GetKeyDown. Using GetKey would return true multiple times, which would rapidly toggle the value with unpredictable results.

That being said, you're using OnMouseDown() which is part of MonoBehaviour... And it doesn't sound like this matches your issue... So all this typing is probably a waste of time.

I guess this would only apply if you're explicitly calling OnMouseDown from another script.

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 avidesk · Oct 21, 2011 at 09:28 PM 0
Share

I don't think this is the case. I am only using two routines in the script. One is On$$anonymous$$ouseDown, and the other is OnGUI, which simply checks the state of '_active', and displays a GUIButton if it is true. There is very little code involved, I doesn't seem likely that there are any variables or functions interfering with one another.

Thanks for the suggestion though.

Given the fact that it works perfectly with any object in the scene except for the one I want (lame), it almost has to be an issue with the object I am attaching the script to, and not the script itself. I just have no idea what could be causing this.

Because this is such an odd issue, I'm sure I sound like a loon, but I promise I have been using Unity for several months with great success until this little hangup!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to detect double and single clicks using javascript? 1 Answer

Detecting a GUI element under the mouse? 1 Answer

Look at mouse 1 Answer

Only updating once during left mouse button being held down. 3 Answers

How to make object clickable when user enter collider ? 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