Hi, I’ve got code that needs access to a list of gameobjects for reference. Although, I am quite new to event systems, and don’t know how to pass parameters through to listeners.
I have to errors with the code below, including:
CS0123, No overload for 'OnClick' matches delegate 'Action'
CS1593, Delegate 'Action' does not take 1 arguments
GameEvents.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameEvents : MonoBehaviour
{
public static GameEvents current;
public GameObject[] SubSettingMenus;
void Awake()
{
current = this;
}
public event Action OnClick;
public void Click()
{
if (OnClick != null)
{
OnClick(SubSettingMenus); //CS0123
}
}
}
ChangeSubSettingsMenu.cs
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.UI;
//using UnityEngine.UIElements;
public class ChangeSubSettingsMenu : MonoBehaviour
{
void Start()
{
GameEvents.current.OnClick += OnClick; //CS1593
}
void OnClick(GameObject[] SubSettingMenus)
{
}
}