- Home /
Set up method parameter in Editor ?
Hi guys, is there a way to setup a function parameter in Editor ?
I don't even know if what I'm asking for is doable so let me explain. Let say I have a script that check a bool in scene and do something is true is returned. Can I imagine something like void CheckAndDoStuff(bool checked){ if(checked){ do stuff} }
and specify the boolean parameters in Editor ? I would like to re-use the same script to check différent flag !
Answer by OutOfRam · Oct 19, 2016 at 05:19 PM
If I understand you correctly, then what you need to do is define a variable at the start of your code and have that variable passed into the function as such;
public bool editorVar = true;
IsTrue(editorVar);
public bool IsTrue(bool parameter)
{
if (parameter == true)
{
//Do Stuff
}
}
I hope this helps!
Answer by Naphier · Oct 20, 2016 at 04:13 AM
Check out UnityEvents and UnityActions. This will allow you to attach method calls in the editor like what you see in the OnClick for Buttons. It's pretty cool. Here's a quick tutorial on it http://naplandgames.com/blog/2016/09/16/quick-tip-using-unity-actions-to-set-default-states-on-objects/
Unless I'm completely misunderstanding what you want to do...
Your answer
Follow this Question
Related Questions
Not able to select booleans in Unity blend tree parameters 0 Answers
Animation/Bool 2 Answers
Mecanim and trigger code 1 Answer
Animator parameter stuck as True 4 Answers
Sequence of methods stored in the list with parameters 1 Answer