A component that listens for trigger enters to collect a specific watermelon. On trigger it increments a global score count, sets a flag indicating the 8th watermelon was collected, plays a sound, and destroys its GameObject on the next update if the flag is set.
using Sandbox;
public sealed class WatermelonCollect8 : Component, Component.ITriggerListener
{
[Property] public SoundEvent melon { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
ScoreManager.WMCount += 1;
ScoreManager.WM8collect = true;
GameObject.PlaySound( melon );
}
protected override void OnUpdate()
{
if ( ScoreManager.WM8collect)
{
GameObject.Destroy();
}
}
}