A PowerUpEffect that spawns extra balls when applied. It stores an optional ball prefab, count, and spread angle and calls the game's SpawnExtraBalls method when applied. It also defines a label and label color for UI.
using Sandbox;
namespace Breakout;
/// <summary>
/// Pickup effect that spawns extra balls, optionally of a specific prefab (a new ball type).
/// </summary>
[Title( "Spawn Ball Effect" ), Category( "Breakout" ), Icon( "add_circle" )]
public sealed class SpawnBallEffect : PowerUpEffect
{
[Property] public GameObject BallPrefab { get; set; }
[Property] public int Count { get; set; } = 1;
[Property] public float SpreadAngle { get; set; } = 20f;
/// <summary>
/// Spawns Count extra balls, optionally of the BallPrefab type, fanned out by SpreadAngle.
/// </summary>
public override void Apply( BreakoutGame game, Paddle paddle )
{
game?.SpawnExtraBalls( BallPrefab, Count, SpreadAngle );
}
public override string Label => "EXTRA BALL";
public override Color LabelColor => new Color( 1f, 0.82f, 0.3f );
}