complex problem
complex problem

Reputation: 11

Best way to organize OnClick events for Unity buttons?

enter image description here

Unity has a component called Button as part of its UI system which you can use to subscribe on-click events to it through the inspector which is incredibly useful.

However, when projects get larger, I run into trouble in many situations:

What are some ways I can work around the problems I've listed above?

Upvotes: 0

Views: 3098

Answers (1)

KiynL
KiynL

Reputation: 4266

Inject event functions inside the code:

public Button playButton; // set button in inspector

public void Start()
{
    playButton.onClick.AddListener(() =>
    {
        transform.position = point1;
        
        // do something..
    });
}

Upvotes: 1

Related Questions