52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
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<TextMeshProUGUI>();
|
|
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<Rigidbody>().useGravity = false;
|
|
transform.GetComponent<FirstPersonController>().enabled = false;
|
|
transform.position = trans.position;
|
|
transform.rotation = trans.rotation;
|
|
}
|
|
void ReturnLook()
|
|
{
|
|
transform.GetComponent<Rigidbody>().useGravity = true;
|
|
transform.GetComponent<FirstPersonController>().enabled = true;
|
|
transform.position= tempPos;
|
|
transform.rotation = RotePos;
|
|
}
|
|
}
|