A game Component that listens for trigger collisions to collect a tofu item. On trigger enter it increments a global ScoreManager.TofuCount, sets ScoreManager.Tofu4collect to true, plays a configured SoundEvent, and in OnUpdate destroys the GameObject if Tofu4collect is true.
using Sandbox;
public sealed class TofuCollect4 : Component, Component.ITriggerListener
{
[Property] public SoundEvent tofu { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
ScoreManager.TofuCount += 1;
ScoreManager.Tofu4collect = true;
GameObject.PlaySound( tofu );
}
protected override void OnUpdate()
{
if ( ScoreManager.Tofu4collect )
{
GameObject.Destroy();
}
}
}