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

63 lines
1.5 KiB
C#
Raw Normal View History

2021-04-06 15:25:53 +02:00
using Ktyl.Util;
2021-03-18 18:25:34 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2021-03-23 16:09:19 +01:00
public class ArrowWall : MonoBehaviour
2021-03-18 18:25:34 +01:00
{
2021-03-23 16:03:18 +01:00
// delay between trap triggering and firing
[SerializeField] private float _delay = 1.0f;
2021-03-18 18:25:34 +01:00
[SerializeField] private TrapSettings _settings;
2021-03-23 16:03:18 +01:00
2021-03-18 18:25:34 +01:00
[SerializeField] private ParticleSystem _particles;
2021-03-22 17:45:42 +01:00
[SerializeField] private Killbox _killbox;
2021-03-18 18:25:34 +01:00
2021-03-23 16:03:18 +01:00
private float? _triggered = null;
2021-03-22 17:45:42 +01:00
2021-04-06 15:25:53 +02:00
[SerializeField] private SerialFloat objectTimeScale;
2021-03-22 17:45:42 +01:00
public void Trigger()
2021-03-18 18:25:34 +01:00
{
// TODO: pressure plate 'click' sound
2021-03-23 16:03:18 +01:00
// set triggered time
_triggered = Time.time;
2021-03-18 18:25:34 +01:00
}
2021-03-22 17:45:42 +01:00
private void Update()
2021-03-18 18:25:34 +01:00
{
2021-03-23 16:03:18 +01:00
if (!_triggered.HasValue) return;
var elapsed = Time.time - _triggered.Value;
2021-03-22 17:45:42 +01:00
2021-03-18 18:25:34 +01:00
// TODO: implications for time freeze
2021-04-06 15:25:53 +02:00
if (elapsed > _delay && objectTimeScale!=0)
2021-03-18 18:25:34 +01:00
{
// TODO: arrow whoosh noises
2021-05-17 18:02:55 +02:00
FMODUnity.RuntimeManager.PlayOneShot(_settings.ArrowWall.FMODEvent, transform.position);
2021-03-18 18:25:34 +01:00
_particles.Play();
// kill player
2021-03-22 17:45:42 +01:00
_killbox.KillPlayer();
2021-03-18 18:25:34 +01:00
2021-03-23 16:03:18 +01:00
Reset();
}
}
private void LateUpdate()
{
if (!_triggered.HasValue) return;
if (_settings.SafeTime > _settings.ArrowWall.SafeResetTime)
{
Reset();
2021-03-18 18:25:34 +01:00
}
}
2021-03-22 17:45:42 +01:00
public void Reset()
2021-03-18 18:25:34 +01:00
{
2021-03-23 16:03:18 +01:00
_triggered = null;
2021-03-18 18:25:34 +01:00
}
2021-03-22 17:45:42 +01:00
}