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