error CS1503: Argument 1: cannot convert from 'void' to 'UnityEngine.Events.UnityAction'

First time coding in C#, Little confused as to why my method is never being called.
I believe the error line to be the following, after searching online I cannot pinpoint my problem.

        Rumbler.onClick.AddListener(TaskOnClick(1));
public class SirenController : MonoBehaviour
{
    public Button RMBLR;
    public Button AIR_HORN;
    public Button MAN;
    public Button WAIL;
    public Button YELP;
    public Button PRTY;

    void Start()
    {
        Button Rumbler = RMBLR.GetComponent<Button>();
        Rumbler.onClick.AddListener(TaskOnClick(1));
    }

    void TaskOnClick(int number)
    {
        switch (number)
        {
            case 1:
                break;
            default:
                break;
        }
    }
}

Thank you for your help.

you need to add an arrow function to that :slight_smile:

Rumbler.onClick.AddListener(() => TaskOnClick(1));
4 Likes

Thank you very much! Enjoy your weekend!

2 Likes