Dev/DevButton.cs
using Sandbox;
public sealed class DevButton : BaseInteract
{
[Property] GameObject Spawn { get; set; } = new();
[Property] string SpawnName { get; set; } = "Item";
[Property] GameObject SpawnPosition { get; set; }
[Property] bool Create { get; set; } = true;
[Property] DevButton AddButton { get; set; }
List<GameObject> SpawnList { get; set; } = new();
public override void OnUse( GameObject player )
{
if( Create )
{
SpawnItem();
}
else
{
RemoveItem();
}
Sound.Play( "breaker.clunk", Transform.Position );
}
void SpawnItem()
{
Log.Info( "Spawning" );
var obj = Spawn.Clone();
obj.Transform.Position = SpawnPosition.Transform.Position;
SpawnList.Add( obj );
}
void RemoveItem()
{
if ( AddButton.IsValid() )
{
foreach ( var obj in AddButton.SpawnList )
{
obj.Destroy();
}
AddButton.SpawnList.Clear();
}
}
}