Skip to content

Instantly share code, notes, and snippets.

View pjmeca's full-sized avatar

Pablo Meca pjmeca

View GitHub Profile
@anastasiadevana
anastasiadevana / 1_ButtonInvoke_Readme.md
Last active April 17, 2024 16:21
Quickly hook any function in your class to a button in the Unity3d Inspector.

How to use

Let's say you have a function called MyFunction, and you want to show a button in the inspector to trigger it.

Just add a "decoy" variable with the [ButtonInvoke] attribute in your script (type of the variable doesn't really matter, but its name will be used as button text.

// "MyFunction" is the name of the function you want to trigger
[ButtonInvoke("MyFunction")] public bool testMyFunction;

// OR use "nameof" to prevent typos