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 RomanorumLegio · Aug 13, 2013 at 11:26 PM · c#errorobjectclickselection

Some Copies of Prefab Detect Clicks But Others Don't

I have several copies of a prefab representing cities in my game, and I want the GUI to update when one is selected. The problem is that some respond while others don't even though they have the same script and hit boxes. I've tried both OnMouseDown and OnMouseOver with mouse input variations of selection.

     void OnMouseOver(){
         if(Input.GetMouseButtonDown(0)){
             selected =! selected;
         }
     }

With the OnMouseOver method, I added a temporary Debug.Log to print the object's name if the mouse was over the object. It worked even for the objects that were not detecting clicks.

Inspector of click detecting copy:

alt text

Inspector of non-click detecting copy

alt text

Thank you in advance. This issue really effects playability.

denver.png (42.5 kB)
topeka.png (42.8 kB)
Comment
Add comment · Show 6
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 Joyrider · Aug 14, 2013 at 12:06 AM 0
Share

maybe the On$$anonymous$$ouseXXX events and Input.GetXXX methods don't play well together.

Anyway, why not just using On$$anonymous$$ouseDown() without the Input? On$$anonymous$$ouseDown already indicates a click on the object.

avatar image RomanorumLegio · Aug 14, 2013 at 12:49 AM 0
Share

I've tried that too with the same results.

avatar image Joyrider · Aug 14, 2013 at 12:51 AM 0
Share

$$anonymous$$aybe your mousebutton is malfunctioning? :p

avatar image RomanorumLegio · Aug 14, 2013 at 01:22 AM 0
Share

Doubt it, given that my mouse works everywhere else.

avatar image vexe · Aug 14, 2013 at 07:44 AM 0
Share

what happens when you hold your click with Input.Get$$anonymous$$ouseButton(0)?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Aug 15, 2013 at 04:04 AM

Often when you have this kind of problem, it is because there is some other collider in the way or there is a problem with the collider. Put this script on an empty game object and then click on any of the cities.

 #pragma strict
     function Update () {
         if (Input.GetMouseButtonDown(0)) { 
             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             var hit : RaycastHit;
             if (Physics.Raycast(ray, hit)) {
                 Debug.Log("name: " + hit.collider.name + "   tag: " + hit.collider.tag);
             }
         }
     }

If it does not hit at all, then there is likely an issue with the collider...not size right, or the normals or facing the wrong direction. If it hit something else besides a city, then you need to address the problem.

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 RomanorumLegio · Aug 17, 2013 at 03:01 AM 0
Share

I tried the script and it is registering the collision on all the cities correctly, so the hit boxes are working. I'm even more confused about what the problem is now.

The script you gave is very versatile and I will probably end up using it several times in the future, so I thank you in advance.

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

17 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

Related Questions

Referencing a variable to a prefab from another script that is applied to multiple game objects 0 Answers

NullReferenceException - When destroying Object 1 Answer

Object Reference not set to an instance of an Object Help 1 Answer

[SOLVED]Object selection scrip doesn't work. 2 Answers

Unknown reason for NullReferenceException error 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