mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-04 01:49:07 +00:00
PAIN
I hate portals. This is just here for refelection.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class PortalManager : MonoBehaviour
|
||||
@@ -23,7 +24,7 @@ public class PortalManager : MonoBehaviour
|
||||
// Gets the location of the player relative to the portal
|
||||
public Vector3 PlayerOffset() => m_PlayerPoint.localPosition;
|
||||
|
||||
static bool s_TeleportedThisFrame = false;
|
||||
static bool s_TeleportAllowed = true;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -51,13 +52,18 @@ public class PortalManager : MonoBehaviour
|
||||
m_PlayerPoint.position = CameraController.Instance().transform.position;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
IEnumerator PortalDelay()
|
||||
{
|
||||
s_TeleportedThisFrame = true;
|
||||
s_TeleportAllowed = false;
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
s_TeleportAllowed = true;
|
||||
}
|
||||
|
||||
// When something enters the portal
|
||||
private void OnTriggerEnter(Collider other)
|
||||
private void OnTriggerEnter(Collider other) => AttemptToTeleportPlayer(other);
|
||||
//private void OnTriggerStay(Collider other) => AttemptToTeleportPlayer(other);
|
||||
|
||||
private void AttemptToTeleportPlayer(Collider other)
|
||||
{
|
||||
// Changing the state if it is not the player will causes issues
|
||||
if (other.CompareTag(PlayerMovement.Object().tag) == false) { return; }
|
||||
@@ -66,8 +72,11 @@ public class PortalManager : MonoBehaviour
|
||||
Vector3 difference = PlayerMovement.Pos() - transform.position;
|
||||
|
||||
// If this is true the player has crossed the portal
|
||||
if (PlayerMovement.CanGoThroughPortals() && s_TeleportedThisFrame == true)
|
||||
if (s_TeleportAllowed == true)
|
||||
{
|
||||
//
|
||||
StartCoroutine(PortalDelay());
|
||||
|
||||
// Rotates the player
|
||||
float rotDif = -Quaternion.Angle(transform.rotation, m_OtherManager.transform.rotation);
|
||||
rotDif += 180.0f;
|
||||
|
||||
38
Assets/Scripts/RoomController.cs
Normal file
38
Assets/Scripts/RoomController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable] public struct RoomEnteranceInfo
|
||||
{
|
||||
[SerializeField] GameObject m_ExitRoom;
|
||||
[SerializeField] RoomEnterance m_RoomExit;
|
||||
[SerializeField] uint m_ExitID;
|
||||
|
||||
public uint ID => m_ExitID;
|
||||
public bool PlayerIsLeaving() => m_RoomExit.IsLeaving();
|
||||
}
|
||||
|
||||
public class RoomController : MonoBehaviour
|
||||
{
|
||||
[Header("")]
|
||||
[SerializeField] RoomEnteranceInfo[] m_Enterances;
|
||||
|
||||
bool m_IsMainRoom = false;
|
||||
|
||||
public void SetAsMainRoom()
|
||||
{
|
||||
m_IsMainRoom = true;
|
||||
|
||||
// Spawn all the rooms
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
foreach (RoomEnteranceInfo info in m_Enterances)
|
||||
{
|
||||
if (info.PlayerIsLeaving())
|
||||
{
|
||||
Debug.Log("KDJHSKGJDFHSKGJhk");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RoomController.cs.meta
Normal file
11
Assets/Scripts/RoomController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 036543747b829e64bb786bd33b3fd84e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/RoomEnterance.cs
Normal file
25
Assets/Scripts/RoomEnterance.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RoomEnterance : MonoBehaviour
|
||||
{
|
||||
[Header("Triggers")]
|
||||
[SerializeField] TriggerTracker m_TriggerA;
|
||||
[SerializeField] TriggerTracker m_TriggerB;
|
||||
|
||||
bool m_PlayerIsLeaving = false;
|
||||
|
||||
public bool IsLeaving() => m_PlayerIsLeaving;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_TriggerB.State() == true && m_TriggerA.State() == false)
|
||||
{
|
||||
m_PlayerIsLeaving = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
m_PlayerIsLeaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RoomEnterance.cs.meta
Normal file
11
Assets/Scripts/RoomEnterance.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d297aa0692a376f49ae09d9930ab35a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/TriggerTracker.cs
Normal file
13
Assets/Scripts/TriggerTracker.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TriggerTracker : MonoBehaviour
|
||||
{
|
||||
private bool m_IsTriggered = false;
|
||||
|
||||
public bool State() => m_IsTriggered;
|
||||
|
||||
private void OnTriggerEnter(Collider other) => m_IsTriggered = true;
|
||||
private void OnTriggerExit(Collider other) => m_IsTriggered = false;
|
||||
}
|
||||
11
Assets/Scripts/TriggerTracker.cs.meta
Normal file
11
Assets/Scripts/TriggerTracker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b5b43a389308414db36de8ea7a8f372
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user