- Home /
Update editorscript if gameobject is manipulated.
I have a editor script that draws a line render between 2 points, the user can manipulate the whole game object, or 2 handles that are used as start and end point for the line renderer.
Now when the object or handles are moved, the linerender stays in place until I edit any of its script settings.
Is there a way to know if a object has been modified in any way so I can trigger my script to update?
Answer by kevork · Sep 21, 2011 at 07:11 PM
In your editor class, save the last position of the object. If it's changed, update the line renderer.
private Vector3 lastPos;
private GameObject _target;
void OnEnable()
{
_target = (GameObject)target;
lastPos = _target.gameObject.transform.position;
}
void OnSceneGUI() {
if(_target.gameObject.transform.position != lastPos) {
// Update your end point positions
}
// Draw your lines
}
thanks, It only works when the object with the script attached is selected. Any way to make this work when a child is moved? Or will I have to write separate scripts for that?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Cloning GameObjects with custom inspector script attached 0 Answers
CustomEditor show an instance of a Class inside a Class 0 Answers
Preview Window in Editor 2 Answers
The parallel function to Selection.activeObject in the Inspector? 0 Answers