• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Image on UI doesn't stretch when objects it's on is stretched. 0 Answers

Instantiating Image makes whole Canvas disappear in Playmode 1 Answer

Ui image appear and disappear on trigger 1 Answer

How to draw UI images with command buffers? 0 Answers

Canvas, instantiate and adjust size of image to fit parent 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges