Jajan
Jajan

Reputation: 926

Binding function to toggle control in unity custom editor

I am making a custom editor in unity with a toggle control. I want to bind a method to the toggle control which will be executed, whenever there is a change in value of toggle.

Can someone tell me how to do it?

Upvotes: 0

Views: 538

Answers (1)

Universus
Universus

Reputation: 406

You can listen in update() for change of toggle or better way is to simply execute method whenever you need via your script control. (You can set this script to any objet and then in game mode try press these checkboxes.)

using UnityEngine;

public class test : MonoBehaviour {

public bool editorStart = false;
public bool editorExit = false;

// Update is called once per frame
void Update () {

    if (editorStart)
    {
        Debug.Log("editorStart changed to TRUE");
        editorStart = false;
    }
    if (editorExit)
    {
        Debug.Log("editorExit changed to TRUE");
        editorExit = false;
    }
}

//better way
public void EditorStart()
{
    //do you stuff
}

public void EditorExit()
{
    //do you stuff
}
}

Upvotes: 1

Related Questions