revival/game/Assets/Scripts/Traps/ArrowWall.cs

63 lines
1.5 KiB
C#

using Ktyl.Util;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowWall : MonoBehaviour
{
// delay between trap triggering and firing
[SerializeField] private float _delay = 1.0f;
[SerializeField] private TrapSettings _settings;
[SerializeField] private ParticleSystem _particles;
[SerializeField] private Killbox _killbox;
private float? _triggered = null;
[SerializeField] private SerialFloat objectTimeScale;
public void Trigger()
{
// TODO: pressure plate 'click' sound
// set triggered time
_triggered = Time.time;
}
private void Update()
{
if (!_triggered.HasValue) return;
var elapsed = Time.time - _triggered.Value;
// TODO: implications for time freeze
if (elapsed > _delay && objectTimeScale!=0)
{
// TODO: arrow whoosh noises
FMODUnity.RuntimeManager.PlayOneShot(_settings.ArrowWall.FMODEvent, transform.position);
_particles.Play();
// kill player
_killbox.KillPlayer();
Reset();
}
}
private void LateUpdate()
{
if (!_triggered.HasValue) return;
if (_settings.SafeTime > _settings.ArrowWall.SafeResetTime)
{
Reset();
}
}
public void Reset()
{
_triggered = null;
}
}