Is it possible/sane to write a editor script that will change a game object’s material via a public enum and to then display it with that material/color in the editor?
So if I write like this I can get a drop down menu in the editor for colors.
public class PowerUpEditorScript : MonoBehaviour {
public enum ColorEnum{Red, Blue, Green};
public ColorEnum Colors;
void Update() {
}
That’s fine and all, I get it to show.
But I was thinking about making the colors for the material to change in editor. And I guess this would be possible with the usage of
[ExecuteInEditMode]
public class PowerUpEditorScript : MonoBehaviour {
...
Before the class declaration. But where would you put the code for the color change? Do you do it update or is this crazy?
void Update () {
if (Colors == Green) {
MyGameObject.GetComponent<Renderer>().material = MyGreenMaterial; //or something similar
}
}
My project doesn’t hang and fall on this, put I’m just curious how ExecuteInEditMode could be used for making stuff more more intuitiv. Or if it’s best to stay clear.
Objects with different materials will have different functions. But I’m thinking their functions will be contained in a different script file so nothing weird happens while executing in editor.