48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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<AudioSourceDelayedScript>();
|
|
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<AudioSourceDelayed>().Clip.Length + Actor.As<AudioSourceDelayed>().Delay);
|
|
}
|
|
|
|
public override void OnFixedUpdate()
|
|
{
|
|
if (FlaxEngine.Time.GameTime >= PlayStartTime)
|
|
{
|
|
PlayStartTime = float.MaxValue;
|
|
Actor.As<AudioSourceDelayed>().Play();
|
|
}
|
|
}
|
|
}
|
|
}
|