2021-03-03 13:53:52 +01:00
|
|
|
using System;
|
2021-02-15 10:44:04 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System.Linq;
|
2021-03-03 13:53:52 +01:00
|
|
|
using Ktyl.Util;
|
2021-02-15 10:44:04 +01:00
|
|
|
|
|
|
|
public class SafeZone : MonoBehaviour
|
|
|
|
{
|
2021-03-03 13:53:52 +01:00
|
|
|
[SerializeField] private SerialVector3 _respawnPosition;
|
2021-03-17 19:04:31 +01:00
|
|
|
[SerializeField] private SerialFloat _safeTime;
|
|
|
|
|
|
|
|
private const string PLAYER = "Player";
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (other.gameObject.CompareTag(PLAYER))
|
|
|
|
{
|
|
|
|
// start counting safe time when we enter a safe zone
|
|
|
|
_safeTime.Value = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-02-15 10:44:04 +01:00
|
|
|
|
2021-03-03 13:53:52 +01:00
|
|
|
private void OnTriggerStay(Collider other)
|
2021-02-15 10:44:04 +01:00
|
|
|
{
|
2021-02-15 17:23:29 +01:00
|
|
|
// Check if other game object is Player.
|
2021-03-17 19:04:31 +01:00
|
|
|
if (other.gameObject.CompareTag(PLAYER))
|
2021-02-15 14:14:42 +01:00
|
|
|
{
|
2021-03-03 13:53:52 +01:00
|
|
|
_respawnPosition.Value = other.gameObject.transform.position;
|
2021-03-17 19:04:31 +01:00
|
|
|
|
|
|
|
// TODO: does this have implications for the time freeze ability?
|
|
|
|
_safeTime.Value += Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
{
|
|
|
|
if (other.gameObject.CompareTag(PLAYER))
|
|
|
|
{
|
|
|
|
// reset safe time when we leave safe zone
|
|
|
|
_safeTime.Value = -1;
|
2021-02-15 10:44:04 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-12 16:58:18 +01:00
|
|
|
}
|