Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 FallingRocketGames · Jan 17, 2018 at 02:38 PM · uicanvastriggersui imagecollider 2d

2D Collider/Trigger on Canvas

Hi there, I'm making a little simulator and I depend on a pressure gauge to activate/deactivate some elements on my scene, this gauge is shown in a UI canvas, so far I've been using some math within the update method but I want to see if I can enhance it by using some triggers on my gauge.

Problem is that I can't find a way for the needle to collide with the green bar, depending on the hierarchy arrange it simply goes over or under the bar but never collides, both of them are in the UI layeralt text

How can I set this up? The needle has a 2d RigidBody 2D as kinematic with continuos detection and for the other colliders I have them as box colliders also tried with rigidbody 2d attached to the images and nothing seems to work, I did check the layer collision matrix and is set to UI/UI what else I'm I missing here, thanks a lot!!!

pessure.png (174.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Diukrone · Jan 17, 2018 at 06:42 PM

The better way, to my way of to code, is to do checks on code, using SmoothDamp. So when pressure reach some value, it triggers an event on or off. So trigger do calls for animations on GUI element. I dont know to much about 2D Physics, so i cant help much ^^ desires to you good luck

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 FallingRocketGames · Jan 17, 2018 at 07:46 PM 0
Share

Thank you, I'll check that option :D

avatar image
0

Answer by FallingRocketGames · Jan 17, 2018 at 09:33 PM

So my workaround was to use 3D colliders instead and extend them over the Z axis in such way that the needle was unable to miss it, can't say if this was the best way to do this but it worked, yet I'm still curious as why the 2D collider didn't work in my UI.

alt text

Other question, do I need to make a script for each trigger? I made a script for each one of the triggers and attached it to it's respective game object like so:

    private void OnTriggerEnter(Collider needle)
 {
     if (needle.gameObject.tag == "Needle")
     {
         print("Max Pressure Reached"); 
         //Some more instructions related to the active trigger 9, 7, 5, 4, 0...           
     }
 }

and so forth with the other ones :( how can I put them all in a single script?


pressure.png (188.5 kB)
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 Diukrone · Jan 17, 2018 at 11:50 PM 0
Share

I am happy that you got a solution! I am curious also that 2D colliders not worked. Yes, you can put many scripts inside, just use in FixedUpdate a call for calculations. For example, you can use the call OnTriggerEnter(); following the logic above:

 void FixedUpdate()
 
 {
       method1();
 
        method2();
 }
 
 void method1()
 {
 }
 
 void method2()
 {
 }
 
 

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

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

Difficulties with world space canvas interaction 1 Answer

UI - clamp the movement of a panel 0 Answers

Display loaded UI Image in Container with native size 0 Answers

Converting to "Rect Transform" permanently deleted part of my project 0 Answers

UI Image tries to 'fit' source image ignoring transparent pixels and stretches it 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