revival/game/Assets/Scripts/Checkpoint/SafeZone.cs

44 lines
1.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Ktyl.Util;
public class SafeZone : MonoBehaviour
{
[SerializeField] private SerialVector3 _respawnPosition;
[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;
}
}
private void OnTriggerStay(Collider other)
{
// Check if other game object is Player.
if (other.gameObject.CompareTag(PLAYER))
{
_respawnPosition.Value = other.gameObject.transform.position;
// 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;
}
}
}