Component attached to a trigger that increments a global watermelon count when something enters, sets a WM5collect flag, plays a configured sound, and destroys the game object after the flag is set.
using Sandbox;
public sealed class WatermelonCollect5 : Component, Component.ITriggerListener
{
[Property] public SoundEvent melon { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
ScoreManager.WMCount += 1;
ScoreManager.WM5collect = true;
GameObject.PlaySound( melon );
}
protected override void OnUpdate()
{
if ( ScoreManager.WM5collect)
{
GameObject.Destroy();
}
}
}