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

47 lines
1.0 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class SafeZone : MonoBehaviour
{
private GameObject player;
private bool isSafe = false;
public Vector3 respawnPoint;
public Vector3 playerPos;
public List<Vector3> lastPlayerPos = new List<Vector3>();
private void Start()
{
player = GameObject.Find("Player");
}
private void OnTriggerEnter(Collider other)
{
isSafe = true;
}
private void OnTriggerExit(Collider other)
{
isSafe = false;
}
private void FixedUpdate()
{
if (isSafe == true)
{
playerPos = player.transform.position;
lastPlayerPos.Add(playerPos);
respawnPoint = lastPlayerPos.Last();
Debug.Log("Player Position: X = " + playerPos.x + " --- Y = " + playerPos.y + " --- Z = " + playerPos.z + " --- RespawnPoint = " + respawnPoint);
}
}
public Vector3 safeSpawn()
{
return respawnPoint;
}
}