90 lines
2.6 KiB
C#
90 lines
2.6 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 EventInstance SpaceMusic;
|
|
|
|
private bool musicStarted = false;
|
|
private void Awake()
|
|
{
|
|
PortalEntrance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.PortalEnter);
|
|
|
|
SpaceMusic = AudioManager.Instance.CreateInstance(FMODEvents.Instance.Kosmos);
|
|
SpaceMusic.setParameterByName("KosmosMusicVolume", 1.0f);
|
|
}
|
|
|
|
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();
|
|
|
|
if (!musicStarted)
|
|
{
|
|
SpaceMusic.start();
|
|
musicStarted = true;
|
|
}
|
|
|
|
// Fade music in on entering
|
|
SpaceMusic.setParameterByName("KosmosMusicVolume", 0f);
|
|
|
|
}
|
|
|
|
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();
|
|
// Fade music out on leaving
|
|
SpaceMusic.setParameterByName("KosmosMusicVolume", 1.0f);
|
|
}
|
|
|
|
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.");
|
|
}
|
|
} |