stageEvents/StageEventMushrooms.cs

A stage event that spawns mushroom enemies over time. On Start it plays a UI sound, posts a local chat message, sets a 10s lifetime and begins a spawn timer; Update spawns a mushroom every 0.25s while hosted and removes the event after the lifetime.

Networking
using System;
using System.Reflection;
using Sandbox;

public class StageEventMushrooms : StageEvent
{
	private TimeSince _timeSinceMushroom;

	public override void Start( int randSeed )
	{
		base.Start( randSeed );

		Manager.Instance.PlaySfxUIRpc( "mushrooms", pitch: Game.Random.Float( 0.95f, 1.05f ), volume: 0.75f );

		Manager.Instance.Chat.AddLocalChatMessage( "Strange mushrooms are growing...", from: "" );

		Lifetime = 10f;

		_timeSinceMushroom = 0f;
	}

	public override void Update()
	{
		base.Update();

		if( TimeSinceStart > Lifetime )
		{
			Manager.Instance.RemoveEvent( EventType );
		}

		if ( !Networking.IsHost )
			return;

		if ( _timeSinceMushroom > 0.25f )
		{
			Manager.Instance.SpawnEnemy( EnemyType.Mushroom, Manager.Instance.GetRandomSpawnPos( buffer: 5f ) );

			_timeSinceMushroom = 0f;
		}
	}

	public override void Remove()
	{
		base.Remove();

	}
}