- Home /
Question by
quansatthu · Dec 22, 2014 at 12:59 PM ·
inspectordelegate
Use variable value in a anonymous methods
Hello,
I'm creating an inspector to set the value of a delegate member of a class
public delegate void MyDelegate ();
public class MyClass {
MyDelegate del;
}
I use this (just example) to set the delegate
[CustomInspector(typeof(MyClass))]
public class MyInspector : Editor {
float val;
public override void OnInspectorGUI () {
MyClass t = target as MyClass
//do something
if (GUILayout.Button ("Set Delegate")) {
t.del = () => { Debug.Log (val); };
}
}
}
Then when I run the delegate in game, a null reference error occured. I just want to use the value of val as a constant. How can I solve this?
Please help.
Thanks in advance.
Comment
That null reference error is unlikely to be related to val. I'd sooner suspect from the as cast to $$anonymous$$yClass.
Your answer
Follow this Question
Related Questions
Action delegate doesn't show in inspector. 1 Answer
Unity editor inspector delegate / function pointer? 2 Answers
Delegates in the Inspector 1 Answer
How do I create a JavaScript class that creates an object with viewable variables in the inspector? 3 Answers
Why is my class hidden in inspector with C# and not JS? 1 Answer