52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class BasicPortal : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private BasicPortal linkedPortal;
|
||
|
public float _portalCooldown = 5.0f;
|
||
|
private bool _isPortalEnabled;
|
||
|
private float _lastUsed;
|
||
|
private bool _justUsed;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
_isPortalEnabled = true;
|
||
|
}
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
if (other.gameObject.tag == "Player" && _isPortalEnabled)
|
||
|
{
|
||
|
Debug.Log("Player stepped into portal");
|
||
|
_justUsed = true;
|
||
|
linkedPortal._isPortalEnabled = false;
|
||
|
_isPortalEnabled = false;
|
||
|
_lastUsed = Time.time;
|
||
|
linkedPortal._lastUsed = Time.time;
|
||
|
|
||
|
Debug.Log("Cooldown started");
|
||
|
|
||
|
other.transform.position = new Vector3(linkedPortal.transform.position.x, other.transform.position.y, linkedPortal.transform.position.z);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (_justUsed)
|
||
|
{
|
||
|
if (_lastUsed + _portalCooldown < Time.time)
|
||
|
{
|
||
|
Debug.Log("Portals enabled again");
|
||
|
_isPortalEnabled = true;
|
||
|
linkedPortal._isPortalEnabled = true;
|
||
|
_justUsed = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|