Tofu/TofuCollect7.cs

A component that listens for trigger collisions to mark a specific tofu collectible as collected. On trigger enter it increments a global TofuCount, sets a Tofu7collect flag on ScoreManager, and plays a sound. During updates it destroys its GameObject once the flag is set.

using Sandbox;

public sealed class TofuCollect7 : Component, Component.ITriggerListener
{
	[Property] public SoundEvent tofu { get; set; }
	void ITriggerListener.OnTriggerEnter( Collider collision )
	{
		ScoreManager.TofuCount += 1;
		ScoreManager.Tofu7collect = true;
		GameObject.PlaySound( tofu );
	}
	protected override void OnUpdate()
	{

		if ( ScoreManager.Tofu7collect )
		{
			GameObject.Destroy();

		}
	}
}