Skip to content

BehaviourButton

Matheus Lessa edited this page Feb 2, 2018 · 7 revisions

BehaviourButton

If you need to execute a piece of code while in Unity Editor, you can simply put the attribute [Button] above a function. Doing that, a button will show on its inspector and clicking it will run that function.

using UnityEngine;
using BitStrap;

public sealed class MyScript : MonoBehaviour
{
    [Button]
    public void SomeFunction()
    {
        Debug.Log( "Hello!" );
        // Some code here!
    }
}

With this sample code, MyScript's inspector will look like:

BehaviourButton

By pressing the Some Function button, Hello! will be print on the console and whatever other code you put there, will also execute.

Clone this wiki locally