56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.XR.CoreUtils;
|
|
using UnityEngine;
|
|
|
|
public class SpaceEnterCollider : MonoBehaviour
|
|
{
|
|
public GameObject InstructionText;
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
XROrigin player = other.GetComponent<XROrigin>();
|
|
if (player == null) return;
|
|
|
|
// Get player's Z rotation (in degrees)
|
|
float playerZ = player.transform.rotation.eulerAngles.z;
|
|
|
|
if (Mathf.Approximately(playerZ, 0f))
|
|
{
|
|
InstructionText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
|
//Debug.Log("Instruction text rotation" + InstructionText.transform.rotation);
|
|
}
|
|
else
|
|
{
|
|
InstructionText.transform.rotation = Quaternion.Euler(0f, 0f, -180f);
|
|
//Debug.Log("Instruction text rotation" + InstructionText.transform.rotation);
|
|
}
|
|
|
|
GravityHandler playerGravity = other.GetComponent<GravityHandler>();
|
|
if (playerGravity != null)
|
|
{
|
|
playerGravity.isInSpace = true;
|
|
}
|
|
Debug.Log(other + " entered space.");
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
XROrigin Player = other.GetComponent<XROrigin>();
|
|
if (Player == null) return;
|
|
|
|
GravityHandler playerGravity = other.GetComponent<GravityHandler>();
|
|
if (playerGravity != null)
|
|
{
|
|
StartCoroutine(DelayExit(playerGravity));
|
|
//playerGravity.AdjustGravity(new Quaternion()); // Set Gravity back to default
|
|
}
|
|
Debug.Log(other + " left space.");
|
|
}
|
|
|
|
private IEnumerator DelayExit(GravityHandler playerGravity)
|
|
{
|
|
yield return new WaitForSeconds(1f); // Wait for 1 second
|
|
playerGravity.isInSpace = false;
|
|
Debug.Log("Default gravity restored after 1 second.");
|
|
}
|
|
} |