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

60 lines
1.3 KiB
C#
Raw Normal View History

2021-03-18 18:25:34 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
2021-03-23 16:03:18 +01:00
using UnityEditorInternal;
2021-03-18 18:25:34 +01:00
using UnityEngine;
2021-03-22 17:45:42 +01:00
public partial 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
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-03-23 16:03:18 +01:00
if (elapsed > _delay)
2021-03-18 18:25:34 +01:00
{
// TODO: arrow whoosh noises
_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
}