using FlaxEngine; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Game; public class AudioSourceDelayed : AudioSource { public float Delay = 0f; public override void OnBeginPlay() { if (Delay >= 0f) { PlayOnStart = false; var script = AddScript(); script.PlayStartTime = Delay + FlaxEngine.Time.GameTime; } base.OnBeginPlay(); } } public class AudioSourceDelayedScript : Script { [NoSerialize] [HideInEditor] public float PlayStartTime = 0f; public override void OnStart() { FlaxEngine.Object.Destroy(Actor, Actor.As().Clip.Length + Actor.As().Delay); } public override void OnFixedUpdate() { if (FlaxEngine.Time.GameTime >= PlayStartTime) { PlayStartTime = float.MaxValue; Actor.As().Play(); } } }