constructed entryway for skywalk

This commit is contained in:
Ranno Samuel Adson
2025-01-15 21:44:46 +02:00
parent 7ba5fe1f30
commit 776c68736d
14 changed files with 1136 additions and 88 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using Unity.XR.CoreUtils;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.XR.Interaction.Toolkit;
@@ -25,34 +26,63 @@ public class MenuTeleportButton : MonoBehaviour
button.onClick.AddListener(TeleportPlayer);
TeleportLocation[] locations = FindObjectsOfType<TeleportLocation>(); // Fetches all teleport locations from scene.
Debug.Log("The amount of teleport locations is " + locations.Length);
//Debug.Log("The amount of teleport locations is " + locations.Length);
foreach (TeleportLocation location in locations) // Finds the target.
{
if (location.Name.Equals(TargetName))
{
target = location;
Debug.Log("Teleport target of " + target.Name + " found.");
//Debug.Log("Teleport target of " + target.Name + " found.");
}
}
if (target == null) Debug.Log("Teleport target of " + TargetName + " not found.");
}
public void SetStateSelected()
{
if (button != null)
{
if (HoverSprite != null)
{
button.targetGraphic.GetComponent<Image>().sprite = HoverSprite;
}
}
}
void Update()
public void SetStateDefault()
{
// Refresh the button state.
button.interactable = false;
button.interactable = true;
if (NormalSprite != null)
{
button.targetGraphic.GetComponent<Image>().sprite = NormalSprite;
}
}
private void TeleportPlayer()
{
Debug.Log("Teleport button clicked");
//Debug.Log("Teleport button clicked");
if (target != null && Player != null && Player.Camera != null)
{
// Teleport the XR Origin to the specified coordinates.
Player.transform.position = target.transform.position;
Player.Camera.transform.rotation = target.transform.rotation;
// Calculate the rotation offset needed for the player
Vector3 targetEulerAngles = target.transform.rotation.eulerAngles;
Vector3 currentCameraEulerAngles = Player.Camera.transform.rotation.eulerAngles;
// Determine the rotation delta around the Y-axis
float rotationDeltaY = targetEulerAngles.y - currentCameraEulerAngles.y;
// Apply the rotation delta to the XR Origin
Player.transform.Rotate(0, rotationDeltaY, 0, Space.World);
// Refresh the button state.
button.interactable = false;
button.interactable = true;
}
}
}