Home > OS >  Unity Button onClick() only showing default functions
Unity Button onClick() only showing default functions

Time:05-31

I'm trying to execute a function using a Button in Unity, but the dropdown menu for the funtions only shows me the default functions that all GameObjects have

I have created an empty GameObject that has the HighscoreList script and draged this object onto the onClick() Object selector, but I can't find any of the functions that I created

What the editor shows me:

enter image description here

The function im trying to call:

public void AddItem(int score, string name)
   {
       Node n = new Node(new HighscoreData(score, name));
       start = start.addItem(n);
   }

CodePudding user response:

Through unity event you can only have functions with a maximum of 1 parameter.

CodePudding user response:

If the script does not compile errors and inherits MonoBehavior. This reason may be caused by directly mounting the script to the OnClick event. However, the OnClick event should use the GameObject containing the script. Here are relevant steps:

  1. Mount the script on the parent object.

enter image description here

  1. GameObject should be mounted on the OnClick event.

enter image description here

  1. The results are as follows.

enter image description here

  • Related