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:
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:
- Mount the script on the parent object.
- GameObject should be mounted on the OnClick event.
- The results are as follows.