E_ElecCompetition/Electrical_inspectionCompet.../Assets/Script/KDLCamera/CameraManager.cs

60 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Threading.Tasks;
public class CameraManager : MonoBehaviour
{
[SerializeField] Button Btn;
[SerializeField] Transform trans;
[SerializeField] Vector3 tempPos;
[SerializeField] Transform Player;
Quaternion RotePos;
//TextMeshProUGUI text;
private async void Start()
{
await Task.Delay(100);
BtnOnClick(UIManager.Instance.bottomCotroller.BirdEyeView);
UIManager.Instance.ToolsItemManager.SwitchAllToolItems();
}
/// <summary>
/// µ÷Óø©î«¸³Öµ
/// </summary>
/// <param name="to"></param>
public void BtnOnClick(Toggle to)
{
to.gameObject.SetActive(true);
//text = Btn.GetComponentInChildren<TextMeshProUGUI>();
to.onValueChanged.AddListener((x) =>
{
if (x)
{
OverLook();
}
else
{
ReturnLook();
}
});
tempPos = Player.transform.position;
RotePos = Player.transform.rotation;
}
void OverLook()
{
Player.transform.GetComponent<Rigidbody>().useGravity = false;
Player.transform.GetComponent<FirstPersonController>().enabled = false;
Player.transform.position = trans.position;
Player.transform.rotation = trans.rotation;
}
void ReturnLook()
{
Player.transform.GetComponent<Rigidbody>().useGravity = true;
Player.transform.GetComponent<FirstPersonController>().enabled = true;
Player.transform.position = tempPos;
Player.transform.rotation = RotePos;
}
}