UI buttons to work with mirrors

UI buttons to work with mirrors

Trying to get my mirrors setup with UI buttons. Not having much luck with udon graph. I have one set of mirrors HQ & LQ. I’m trying To run it like this. HQ button turn on or off & LQ button turn off. Same as LQ button turn on or off & HQ button turn off. If you are confused go to the black cat and used the UI buttons for the mirrors. That what trying figure out how to set it up. Just with 1 set of mirrors and then how to set it up for the 2 sets & 3 set of mirrors.

My Buttons Setup
Screenshot 2021-01-04 103840
Screenshot 2021-01-04 103939


I was gonna show a method without using Udon Graphs first, but the Graph method is little cleaner so here it is!

You have a UI shape & box collider on your canvas & their layers are set to default, so I’m gonna assume you watched a tutorial, so I’ll skip that bit! Just make sure your box collider covers the whole canvas, cuz you can only interact with things that are inside of that collider!

I created an empty GameObject outside of the canvas & put a UdonBehaviour on it.
The Graph on that GameObject has 2 Public GameObject variables that you would drag your HQ Mirror & LQ Mirror GameObjects onto in the inspector tab.
It also has 2 Custom Events “Toggle_HQ_Mirror” & “Toggle_LQ_Mirror” that handle making sure the OTHER mirror is OFF & toggles the Active status of its respective mirror.


Note=> to get the bool nodes search for “bool” then “constant” with nothing selected

On the UI Buttons on the Canvas, in their On Click () section, you would drag the GameObject with the Udon Graph there. Then next to where it says “Runtime Only” Click on “No Function”, then click on “UdonBehaviour” & then scroll all the way down till you see “SendCustomEvent (string)” & select that! Now just put the “Toggle_HQ_Mirror” Custom Event name on the Mirror HQ Button & the “Toggle_LQ_Mirror” Custom Event name on the Mirror LQ Button.

Mirror HQ Button:

Mirror LQ Button:

To set it up to handle multiple mirrors, you could create an empty GameObject & name it something like HQ Mirrors & drag all of the HQ Mirrors into it in the Hierarchy tab & then on the Mirror Controller GameObject instead of dragging a single mirror into the public variable you would drag the HQ Mirrors GameObject with all of the HQ Mirrors in it there instead! it would then turn them all off & on at the same time.

AND HERES THE UGLY OTHER METHOD:
Basically you would have an on & off button for both HQ and LQ that would turn themselves on and off to simulate a toggle. the buttons would look the same so it would look like you are hitting the same button but really its an On or Off button for each Mirror. Just make sure the OFF buttons are set to Inactive by default!

1 Like