TriggerWinHW.cs

Component that listens for trigger enters to mark level completion. On trigger enter it records score, plays particles and sound, applies forces/animation to a skinned model and then loads a configured next scene after a delay.

NetworkingFile Access
using Sandbox;
using static Sandbox.Resources.ResourceGenerator;

public sealed class TriggerWinHW : Component, Component.ITriggerListener

{
	[Property] public SkinnedModelRenderer model { get; set; }
	[Property] public Rigidbody rb { get; set; }
	[Property] public SoundEvent win { get; set; }
	[Property] public static int CurrentLevelIndex = 1;
	[Property] public ParticleSphereEmitter winparticles { get; set; }

	[Property] static Scene ActiveScene { get; set; }

	[Property] public SceneFile nextscene { get; set; }

	[Property] int nextLevelDelay = 3;

	[Property] public ChickenControls chicken { get; set; }
	


	async void ITriggerListener.OnTriggerEnter( Collider other )
	{
		ScoreManager.CurrentScore = chicken.cornpoints;
		winparticles.Enabled = true;
		model.Set( "AnimPar", 6 );
		rb.ApplyForce( Vector3.Backward * 50000 );
		GameObject.PlaySound( win );
		await Task.Delay( 500 );
		rb.GravityScale = 125;
		LoadNextLevel();

	}
	void ITriggerListener.OnTriggerExit( Collider other )
	{
		
		
	}
	async void DelayedMethod()
	{
		
		// Wait for 2 seconds
		await Task.Delay( nextLevelDelay );

		// Code to run after delay
		var options = new SceneLoadOptions();

		options.SetScene( nextscene);
		Scene.Load( options );
		Sound.StopAll( 0f );
	}
	void LoadNextLevel()
	{
		DelayedMethod();
		
	}


}