using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Fieldobservation : MonoBehaviour { /// /// 玩家相机 /// public Camera Camera; /// /// 警告按钮 /// public Button ExclamationPointBtn; /// /// 封印动画 /// public SkinnedMeshRenderer SkinnedMeshRenderer; bool isclick; /// /// 上下梯子按钮 /// public Button UpladderBtn; public Button DownladderBtn; /// /// 上梯子后坐标 /// public Transform UptheladderPos; /// /// 梯子点位 /// public Transform LadderPos; /// /// 变电箱门锁 /// public Transform Doorlock; /// /// 变电箱左门 /// public Transform DoorOfCabinet; /// /// 打开封印 /// bool isOpenLock; void Start() { UpladderBtn.onClick.AddListener(() => { Camera.gameObject.transform.position = UptheladderPos.transform.position; DownladderBtn.gameObject.SetActive(true); UpladderBtn.gameObject.SetActive(false); }); DownladderBtn.onClick.AddListener(() => { Camera.gameObject.transform.position = new Vector3(303.5654f, 1.200012f, 163.5107f); DownladderBtn.gameObject.SetActive(false); UpladderBtn.gameObject.SetActive(true); }); } void Update() { if (Input.GetMouseButtonDown(0)) {//Camera.transform.forward Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool raycast = Physics.Raycast(ray, out hit); if (raycast) { if (hit.collider.gameObject.name == "柜门_封印") { //播放动画 StartCoroutine(OpenLock()); Debug.Log(hit.collider.gameObject.name); //SkinnedMeshRenderer.SetBlendShapeWeight(100, 3); } } } } /// /// 打开封印动画 /// /// IEnumerator OpenLock() { for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.01f); SkinnedMeshRenderer.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(2f); SkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.637f, 0.12f, -0.015f),1f); yield return new WaitForSeconds(3f); Destroy(SkinnedMeshRenderer); StartCoroutine(OpenDoor()); } IEnumerator OpenDoor() { yield return new WaitForSeconds(1f); Doorlock.transform.DOLocalRotate(new Vector3(160, 0, 0), 2f); yield return new WaitForSeconds(3f); DoorOfCabinet.transform.DOLocalRotate(new Vector3(-90, 160, 0), 2f); } /// /// 柜门先后动画 /// /// //IEnumerator OpenDoor() //{ // Doorlock069.DOLocalRotate(new Vector3(150, 0, 0), 1f); // yield return new WaitForSeconds(2f); // LeftDoor.DOLocalRotate(new Vector3(150, 0, 0), 2f); //} /// /// 用户触发 /// /// private void OnTriggerEnter(Collider other) { if (other.name == "LadderPos") { UpladderBtn.gameObject.SetActive(true); } } /// /// 用户离开npc警告按钮消失 /// /// private void OnTriggerExit(Collider other) { if (other.name == "Man_stand") { ExclamationPointBtn.gameObject.SetActive(false); } if (other.name == "LadderPos") { UpladderBtn.gameObject.SetActive(false); } } }