75 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using Unity.XR.CoreUtils;
 | |
| using UnityEngine;
 | |
| using FMOD.Studio;
 | |
| 
 | |
| public class SpaceEnterCollider : MonoBehaviour
 | |
| {
 | |
|     public GameObject InstructionText;
 | |
| 
 | |
|     private EventInstance PortalEntrance; 
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         PortalEntrance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.PortalEnter);
 | |
|     }
 | |
| 
 | |
|     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.");
 | |
| 
 | |
|         PortalEntrance.start();
 | |
| 
 | |
|     }
 | |
| 
 | |
|     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.");
 | |
| 
 | |
|         PortalEntrance.start();
 | |
|         
 | |
|     }
 | |
| 
 | |
|     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.");
 | |
|     }
 | |
| } |