It keeps track of its GameObject position, and will send a notification every time it's has traveled a certain distance. The interesting part about it it's that it shows how notifications can be edited by the level designer for maximum flexibility.
/// <summary> /// Hansel script will drop a pebble (trigger an event) whenever a certain distance has been covered /// </summary> public class HanselScript : GuayScript { /// <summary> /// Distance between pebbles /// </summary> public float DistBetweenPebbles; /// <summary> /// Event notified everytime the distance is covered /// </summary> public Notification DropPebbleEvent = "pebbleDropped"; /// <summary> /// Ctor, /// </summary> public HanselScript() { var lastPosition = new Vector3(); var accDistance = 0f; OnAwake = _properties => lastPosition = GameObject.transform.position; OnUpdate = _deltaTime => { accDistance += (GameObject.transform.position - lastPosition).magnitude; if( accDistance >= DistBetweenPebbles ) { accDistance -= DistBetweenPebbles; Notify( DropPebbleEvent ); } lastPosition = GameObject.transform.position; }; } }
No comments :