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