A game component that represents a circular area centered on the entity's world position, with a 2D-position accessor, radius and lifetime. It tracks time since spawn and destroys the GameObject when the lifetime elapses.
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 );
}
}