78 lines
1.7 KiB
C#
78 lines
1.7 KiB
C#
using System.Collections;
|
|
using Obvious.Soap;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
public class PlayerLeaveAreaTeleporter : MonoBehaviour
|
|
{
|
|
public BoolVariable IsInVehicle;
|
|
|
|
public ScriptableEventNoParam OnLeavingAreaEnter;
|
|
|
|
public ScriptableEventNoParam OnLeavingAreaExit;
|
|
|
|
public ScriptableEventNoParam OnLeavingPositionRegister;
|
|
|
|
public FSMVariable PlayerState;
|
|
|
|
public float LeavingTimeCounter = 5f;
|
|
|
|
private Vector3 _EnterPosition;
|
|
|
|
private Vector3 _EnterFWDDir;
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
OnLeavingAreaEnter.OnRaised += OnLeavingAreaEnterOnOnRaised;
|
|
OnLeavingAreaExit.OnRaised += OnLeavingAreaExitOnOnRaised;
|
|
OnLeavingPositionRegister.OnRaised += OnLeavingPositionRegisterOnOnRaised;
|
|
}
|
|
|
|
private void OnLeavingPositionRegisterOnOnRaised()
|
|
{
|
|
_EnterPosition = base.transform.position;
|
|
_EnterFWDDir = base.transform.forward;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
OnLeavingAreaEnter.OnRaised -= OnLeavingAreaEnterOnOnRaised;
|
|
OnLeavingAreaExit.OnRaised -= OnLeavingAreaExitOnOnRaised;
|
|
OnLeavingPositionRegister.OnRaised -= OnLeavingPositionRegisterOnOnRaised;
|
|
}
|
|
|
|
private void OnLeavingAreaEnterOnOnRaised()
|
|
{
|
|
StartCoroutine(WaitToTeleport());
|
|
}
|
|
|
|
private void OnLeavingAreaExitOnOnRaised()
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
|
|
private IEnumerator WaitToTeleport()
|
|
{
|
|
yield return new WaitForSeconds(LeavingTimeCounter);
|
|
Teleport();
|
|
}
|
|
|
|
private void Teleport()
|
|
{
|
|
if (IsInVehicle.Value)
|
|
{
|
|
GetComponent<PlayerVehicleController>().Teleport(_EnterPosition, _EnterFWDDir);
|
|
}
|
|
else
|
|
{
|
|
base.transform.position = _EnterPosition;
|
|
base.transform.rotation = Quaternion.LookRotation(-_EnterFWDDir, Vector3.up);
|
|
}
|
|
OnLeavingAreaExit.Raise();
|
|
}
|
|
}
|