Files

48 lines
902 B
C#
Raw Permalink Normal View History

2025-05-13 05:19:58 +03:00
using UnityEngine;
using System.Collections;
public enum DetonatorState{
Idle,
Wait,
Exploded
}
public class DelayDetonator : MonoBehaviour {
public Explosive target;
private AudioSource _source;
public Predicate trigger;
private DetonatorState _state;
public float delay = 3.0f;
private float timeElapsed = 0;
void Start () {
if(target == null){
target = GetComponentInChildren<Explosive>();
}
_source = GetComponent<AudioSource>();
}
void Update () {
if(_state == DetonatorState.Idle && trigger != null && trigger.Check()){
_state = DetonatorState.Wait;
if(_source != null){
_source.Play();
}
}
if(_state == DetonatorState.Wait){
timeElapsed += Time.deltaTime;
if(timeElapsed >= delay){
_state = DetonatorState.Exploded;
if(_source != null){
_source.Stop();
}
if(target != null){
target.Explode();
}
}
}
}
}