A component that listens for trigger enter events to collect a watermelon. On trigger it increments a global ScoreManager counter, sets a flag, plays a sound, and destroys the game object on the next update if the flag is set.
using Sandbox;
public sealed class WatermelonCollect2 : Component, Component.ITriggerListener
{
[Property] public SoundEvent melon { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
ScoreManager.WMCount += 1;
ScoreManager.WM2collect = true;
GameObject.PlaySound( melon );
}
protected override void OnUpdate()
{
if ( ScoreManager.WM2collect)
{
GameObject.Destroy();
}
}
}