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(); 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(); if (playerGravity != null) { playerGravity.isInSpace = true; } Debug.Log(other + " entered space."); } private void OnTriggerExit(Collider other) { XROrigin Player = other.GetComponent(); if (Player == null) return; GravityHandler playerGravity = other.GetComponent(); 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."); } }