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 !
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 Quick tip: Using Unity Actions to set default states on objects – Napland Games – Blog
Unless I’m completely misunderstanding what you want to do…
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!