Using EditorGUI to manipulate MonoBehaviour GameObject.

Hello everyone,

My script is pretty big, so I'll try me best to narrow it down to the core.

I'm trying to use 3 IntSliders to manipulate a GameObject's color. Here's what I had in a nutshell:

var slideR : float = 255; //Range: 0-255
var slideG : float = 255;
var slideB : float = 255;

function Update(){
    headPart.renderer.material.color.r = slideR/ 255;
    headPart.renderer.material.color.g = slideB/ 255;
    headPart.renderer.material.color.b = slideG/ 255;
}

function OnGUI(){
    slideR = EditorGUI.IntSlider (Rect(850, 500, 200, 20), slideR, 0, 255.0);
    slideG = EditorGUI.IntSlider (Rect(850, 520, 200, 20), slideG, 0, 255.0);
    slideB = EditorGUI.IntSlider (Rect(850, 540, 200, 20), slideB, 0, 255.0);
}

However, this gives me the error of "Unknown identifier: EditorGUI". I've read that I should place the script in my Editor folder, but then it can't be attached to my GameObject anymore. What would be the best way to get around this limitation?

Thanks in advance, Patrick

1 Answer

1

If the intent is to modify the object's properties while the game isn't running, it might be a custom inspector that you're wanting (see the section of the Unity docs titled 'Extending the Editor' for more info).

If however this is intended to be an in-game feature, you might need to use one of the GUI/GUILayout slider functions instead. (Although there isn't an 'integer' version that I'm aware of, you can cast the return value to an int if needed, or just use the range [0, 1] instead.)

Do'w, I didn't even realize there was a GUI.HorizontalSlider. It worked without any additional changes, thanks! =)