Hi everyone,
I’m learning how to make my own editor window.
I’ve made one to achieve some specific manipulations over GOs.
When a GO is selected, I need to display its z coordinate (among other properties). Thus I made a floatfield which displays its transform.position.z. Very simple.
The problem is I cannot modify its z position from that field, neither by typing a value, nor by sliding. The value keeps « sticking » to the actual z coordinate.
How can I make the float field interact with the GO (as in the inspector’s Transform component) ?
And a subsidiary question : you’ll notice that to refresh my window, I’m using Repaint(). But I’m not sure where is the best place to call it : is it at the end of OnGUI() ? Or within the Update() ?
Here is my code :
public GameObject go;
void OnGUI() {
// display selected GO
go = Selection.activeGameObject;
go = (GameObject)EditorGUILayout.ObjectField("Selected GO", go, typeof(Object), true);
if (go) {
// display z pos
float zPos = go.transform.position.z;
zPos = EditorGUILayout.FloatField("z position", zPos);
}
// Repaint(); // refresh window here ?...
}
private void Update() {
Repaint(); // ... or here ?
}
Thanx for any help.