Answers for "unity assign button onclick"

C#
17

unity assign button onclick

public Button yourButton;	

void Start () 
{
	Button btn = yourButton.GetComponent<Button>(); //Grabs the button component
	btn.onClick.AddListener(TaskOnClick); //Adds a listner on the button
}	
void TaskOnClick()
{
	Debug.Log ("You have clicked the button!");
}
Posted by: Guest on February-27-2020

C# Answers by Framework

Browse Popular Code Answers by Language