Answer the question
In order to leave comments, you need to log in
What is the correct way to write onClick(clicked) in Unity?
onClick code doesn't work and I'm attaching an error
public class NewBehaviourScript : MonoBehaviour
{
private Button button;
// Start is called before the first frame update
void Start()
{
button=GetComponent<Button>();
button.clicked.AddListener(setDifficulty);
}
// Update is called once per frame
void Update()
{
}
void setDifficulty()
{
Debug.Log(gameObject.name + "clicked");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question