A component representing a circular area (2D) attached to an entity that expires after a Lifetime. It exposes Position2D which maps to the entity WorldPosition X/Y, a Radius, and destroys the GameObject when its TimeSince spawn exceeds Lifetime.
using Sandbox;
public sealed class SpikerHeadArea : Component
{
public Vector2 Position2D
{
get { return (Vector2)WorldPosition; }
set { WorldPosition = new Vector3( value.x, value.y, WorldPosition.z ); }
}
public float Radius { get; set; }
public float Lifetime { get; set; }
private TimeSince _timeSinceSpawn;
protected override void OnStart()
{
base.OnStart();
_timeSinceSpawn = 0f;
}
protected override void OnUpdate()
{
if ( _timeSinceSpawn > Lifetime )
{
GameObject.Destroy();
}
//Gizmo.Draw.Color = Color.Cyan;
//Gizmo.Draw.LineSphere( WorldPosition, Radius );
}
}