using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class CameraManager : MonoBehaviour { [SerializeField] Button Btn; Transform trans; [SerializeField] Vector3 tempPos; Quaternion RotePos; TextMeshProUGUI text; int sum = 2;//点击的数量 // Start is called before the first frame update private void Start() { text = Btn.GetComponentInChildren(); Btn.onClick.AddListener(() => { if (sum%2==0) { OverLook(); text.text = "正常视图"; } else { ReturnLook(); text.text = "俯瞰图"; } sum++; }); trans = GameObject.Find("overlook").transform; tempPos = transform.position; RotePos = transform.rotation; } void OverLook() { transform.GetComponent().useGravity = false; transform.GetComponent().enabled = false; transform.position = trans.position; transform.rotation = trans.rotation; } void ReturnLook() { transform.GetComponent().useGravity = true; transform.GetComponent().enabled = true; transform.position= tempPos; transform.rotation = RotePos; } }