*
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user