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 layer
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!!!
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
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.
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?