A game component that listens for trigger collisions to collect a Tofu. On trigger it increments a global ScoreManager tofu count, sets a Tofu10collect flag, plays a sound, and then destroys its GameObject on the next update if the flag is set.
using Sandbox;
public sealed class TofuCollect10 : Component, Component.ITriggerListener
{
[Property] public SoundEvent tofu { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
ScoreManager.TofuCount += 1;
ScoreManager.Tofu10collect = true;
GameObject.PlaySound( tofu );
}
protected override void OnUpdate()
{
if ( ScoreManager.Tofu10collect )
{
GameObject.Destroy();
}
}
}