Trying to Associate a method with a button, but it doesn't show up?

I have a public class Playercontroller script that has a function:

void SetCountText(){
	countText.text = "Count: " + count.ToString ();
	if (count >= 10){
		winText.text = "You win!";

But when I created a button, dragged the game object into its “on click” field, and looked for functions under the “PlayerController” script, it didn’t show up.

Anyone know what’s going on?

When setting an event handler in the inspector, the following members of the selected object will be available:

  • Public fields (not C#-style properties)
  • Public methods taking zero or one arguments

In addition, the type (of the field or of the method’s unique argument) has restrictions. I don’t know them, but:


  • int, float, string
  • Components/monobehaviours
  • Most objects from the Projet panel, it seems (AudioClip, Texture, Script)

Doesn’t work:

  • arrays
  • Vector3
  • Most types that aren’t basic, monobehaviour or resource