ar_tourism_flutter_unity/unity/VRProject2/Assets/CH/Scripts/PlayerManager.cs
2025-05-14 17:04:13 +08:00

56 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class PlayerManager : MonoBehaviour
{
//单例
private static PlayerManager instance;
public static PlayerManager Instance
{
get
{
return instance;
}
}
[SerializeField] public Transform player;
[SerializeField] public Transform otherWorld;
[SerializeField] private TMP_Text text;
public Texture2D[] initSprites;
private void Awake()
{
instance = this;
}
void Start()
{
StartCoroutine(RotateWorld());
}
private void Update()
{
if(otherWorld.gameObject.activeSelf){
transform.position = otherWorld.position;
}
}
IEnumerator RotateWorld()
{
yield return new WaitForSeconds(1f);
// 获取player的欧拉角旋转
Vector3 playerRotation = player.rotation.eulerAngles;
// 获取world当前的欧拉角旋转
Vector3 worldRotation = otherWorld.rotation.eulerAngles;
// 只更新y轴旋转保持x和z轴不变
worldRotation.y = playerRotation.y;
// 应用新的旋转
otherWorld.rotation = Quaternion.Euler(worldRotation);
}
}