I would like to know how can I access the gameObject of my Custom Inspector.
Thanks a lot !
I would like to know how can I access the gameObject of my Custom Inspector.
Thanks a lot !
If you have written a custom inspector for the script MyScript, the target variable is of the type MyScript. As long as MyScript is a monobehaviour, you can grab it’s gameObject as normal, you just need the cast to MyScript first. I like to grab the script in OnEnable, and make it available as a field:
[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor {
MyScript script;
GameObject scriptObject;
void OnEnable() {
script = (MyScript) target;
scriptObject = script.gameObject;
}
void OnInspectorGUI() {
...
}
}