- Home /
This question was
closed Apr 14, 2020 at 05:03 PM by
gjf.
Question by
Proxtx · Apr 14, 2020 at 02:36 PM ·
c#eventeventsystemargumentexception
passing function to class
public class option
{
public UnityEvent onclick = new UnityEvent();
public string name;
}
With this code I'm able to pass a funtion to the class but only functions from the same class:
public class objScript : MonoBehaviour
{
public List<option> defaultOptions = new List<option>();
void yey()
{
Debug.Log("YAY");
}
void Start()
{
opti = new option();
opti.name = "Delete";
opti.onclick.AddListener(yey);
defaultOptions.Add(opti);
}}
This won't work:
public class objScript : MonoBehaviour
{
public List<option> defaultOptions = new List<option>();
void Start()
{
options opt = GetComponent<options>();
option opti;
opti = new option();
opti.name = "Delete";
opti.onclick.AddListener(opt.delete); //options.delete is defined
defaultOptions.Add(opti);
}}
ERORR: ArgumentException: Value does not fall within the expected range.
Comment
Follow this Question
Related Questions
passing function to class 1 Answer
ArgumentException: method return type is incompatible 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can I use EventSystems to receive PointerEvents anywhere on screen? 0 Answers