Create a conditional to switch between OnClick and OnPointerDown

Hi folks,

I have a GUI that performs most of its button behavior based on ‘OnClick’, however, there are certain builds of the game where I want the entire GUI to behave with ‘OnPointerDown’ (or ‘OnMouseDown’) instead. I know how to set this behavior up in the editor, specifically for each button, but…

Is there a way to set a global bool/flag, or an override, that will have all buttons in my GUI behave with ‘OnClick’ if true, and ‘OnPointerDown’ if false, for example, without having to create two cases, or edit for each button individually?

Thanks!

You could:

  • Use a preprocessor to change your code compilation based on your build target.
#if SOMETHING
// code
#endif
  • Or you could make it change at runtime by checking a variable inside the function call (OnClick or OnPointerDown) and return immediately without executing the code (the callback would be still be called everytime tho).
void onClickCallback()
{
if(onclick_blocked) return;
// rest of the code
}
  • Or you define different prefabs (with different behaviours) for each build.

  • Or ditch onClick and use only OnPointerDown/OnPointerUp.