Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jrj2211 · Mar 18, 2018 at 05:05 PM · collidermesh colliderclickable

Adding multiple simple mesh colliders to be able to click on an objects parent

Problem

I'm making a god mode type game where you can click on buildings. Currently I'm using box colliders that take up the entire tile that the object sits on, but this results in a lot of misclicks or having to rotate the camera because another box collider is blocking it, despite it being visible.


What I'm doing now

For my first building, I've made a group in Maya called colliders and added two meshes inside of it. These are basically cubes with the edges moved around to match the roof angles.

alt text

Now I'm trying to apply this in Unity, but if I put it on the root of the prefab for the building the collider doesnt show up (the green wireframe) and in game I cannot click on it.

alt text

If I however put it on the collider object in the hierarchy, then it does show up.

alt text

My issue with this is then my check for clicking on the object doesn't work because I'm looking for the clicked object to have a specific script so I can know what type of object was clicked and update the UI. When I was using box colliders, it was on the same gameobject that had my "House" script, which is the top level of the prefab.

 void Update()
     {
         if (Input.GetMouseButtonUp(0))
         {
             if (!EventSystem.current.IsPointerOverGameObject())
             {
                 HideAll();
 
                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 RaycastHit hit;
 
                 if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                 {
                     House h = hit.transform.gameObject.GetComponent<House>();
                     if (h)
                     {
                         ShowHouseInfo(h);
                         return;
                     }
                 }
             }
         }
     }

I could get the parent object and then check for the script but I feel this isn't a great solution because then its dependent on the hierarchy of my model and I don't think code should depend on that.


Question

My question is what would be the proper way of adding a couple basic mesh colliders and then getting what "Prefab" was clicked on? Also, is it better to keep these meshes separate so they are not convex, or combine them together and use a convex collider and should they be in the same FBX file as the model itself?

colliders.png (119.9 kB)
colliders-2.png (181.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

89 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 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 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 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

There is somthing like mesh collider to 2D objects? 2 Answers

Clickable Object Problem - Help 1 Answer

Very Confused About Convex Mesh Collider Result 0 Answers

Collider for rocks. 1 Answer

Mesh collider and jitter 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