A Sandbox game Component that gives a player corn points when a trigger enters. It listens for trigger collisions, checks for the "player" tag, destroys the corn GameObject, plays a sound, and calls Addcornpoints(+25) on a ChickenControls reference.
using Sandbox;
public sealed class CornPoints : Component, Component.ITriggerListener
{
[Property] public SoundEvent corn { get; set; }
[Property] public ChickenControls chicken { get; set; }
void ITriggerListener.OnTriggerEnter( Collider collision )
{
if ( collision.GameObject.Tags.Has( "player" ) )
{
GameObject.Destroy();
GameObject.PlaySound( corn );
chicken.Addcornpoints( +25 );
}
}
}