Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 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 bracciata · Jul 27, 2015 at 02:29 AM · c#unity 5collisioncollidersclick

OnMouseDown with colliders behind the object being clicked

I have on screen buttons which are not currently working because there is collider behind them which is flooring for my platformer. Do you know of a possible work around for this issue.

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 supernat · Jul 27, 2015 at 03:50 AM 0
Share

What kind of buttons?

avatar image bracciata · Jul 27, 2015 at 01:59 PM 0
Share

They're just colliders that are called by on mousedown.

3 Replies

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

Answer by Hexer · Jul 27, 2015 at 03:10 PM

I have stated before that you have to change the transform.position.z value of one of your sprites so that 1 of the sprites don't overlap eachother in 3d space. This time I have added some pictures with instructions to explain how it works.

You can clearly see in the first picture that in the game scene, the green button is infront of the black sprite. But this is not the case in 3d space, in 3d space the black sprite is actually infront of the green button. In the game scene we only changed the order layer to let it seem like it was infront of the black sprite, while this was not the case.

alt text

Now when we change that transform.position.z value to something else. In my case the black sprite Z position was -2 while the GreenButton Z position was 0. So I changed the blacksprite Z position to 1 or higher. Now the Black sprite is actually standing behind the greenbutton in 3d space.

You could also change the button Z position to let it come infront of the black sprite, the same principles are used as above. alt text

Now when I changed the Z position value and click on the button, I would see a value (which I set with GuiText ToString(). This indicates that it worked.


1.png (351.7 kB)
2.png (364.7 kB)
Comment
Add comment · Show 4 · 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 bracciata · Jul 27, 2015 at 06:23 PM 0
Share

$$anonymous$$y objects are already at different z's and it's still not working I have the buttons set 5 and the floors set to 0.

avatar image guilhermecorintho · Aug 15, 2018 at 08:09 PM 0
Share

Thank you, know this z position behaviour helped me alot!

avatar image ProperNovice · May 04, 2021 at 07:43 PM 0
Share

Thank you Hexer

avatar image tonymotion · Oct 15, 2021 at 04:33 AM 0
Share

Thank you, thank you , thank you! This explained the mysterious behavior I was seeing involving overlapping 2D colliders with different Sort Orders but the same Z. You're a sanity saver!

avatar image
2

Answer by AlexGan001 · Jul 28, 2015 at 09:54 AM

I would use a Canvas and the UI Buttons, because they come with their own built in function OnClick() in the editor. If you want the button to stay in one place in the scene, you would select 'World Space' in the Render Mode box.

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
avatar image
0

Answer by Khudere · May 05, 2020 at 04:11 PM

Thanks this helped me! I was trying to play with the layers but forgot to look at the z location

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

29 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

Related Questions

OnCollisionEnter the Enemy Detect Collision but health damage not working but on OnTriggerEnter the health is reducing on punch but collision is not detecting 1 Answer

Particles to play after an object hits the ground (Unity 5) 1 Answer

Freeze Gameobject's position on collision 0 Answers

Reacting to terrain height changes without a rigidbody component 0 Answers

Multiple Colliders On A Single Object Detecting Each Collider In OnTriggerEnter() 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