Merge commit 'e7f8693f' into SamWorkset
This commit is contained in:
@@ -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,20 +26,38 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
public void SetStateDefault()
|
||||
{
|
||||
@@ -47,16 +66,27 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user