A game component that listens for trigger collisions. When an object tagged "player" enters the trigger it destroys its GameObject, plays a configured sound, and adds 100 corn points to a ChickenControls instance.
using Sandbox;
public sealed class CobPoints : Component, Component.ITriggerListener
{
[Property] public SoundEvent cob { get; set; }
[Property] public ChickenControls chicken { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
if ( collision.GameObject.Tags.Has( "player" ) )
{
GameObject.Destroy();
GameObject.PlaySound( cob );
chicken.Addcornpoints( +100 );
}
}
}