Undo.CreateSnapshot Manual     Reference     Scripting  
Scripting > Editor Classes > Undo
Undo.CreateSnapshot

static function CreateSnapshot () : void

Description

Save the current state of all objects set with SetSnapshotTarget to internal snapshot.

See Also: SetSnapshotTarget , RegisterSnapshotTarget.

// Editor Script Side
// Create a position Handle and make the target always look at the position handle.
// This is an editor Script, this should go inside the Editor Folder.

@CustomEditor (LookAtPoint)
class SnapshotTargetEx extends Editor {


function OnSceneGUI () {
Undo.SetSnapshotTarget(target, "Moved Object Around");
target.lookAtPoint =
Handles.PositionHandle (target.lookAtPoint, Quaternion.identity);
if (GUI.changed)
EditorUtility.SetDirty (target);

if(Input.GetMouseButtonDown(0)) {
// Register the undos when we press the Mouse button.
Undo.CreateSnapshot();
Undo.RegisterSnapshot();
}
}
}

And the runtime script that works with this editor Script

// LookAtPoint.js

@script ExecuteInEditMode()

var lookAtPoint = Vector3.zero;

function Update () {
transform.LookAt (lookAtPoint);
}