56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
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);
|
||
}
|
||
} |