using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using UnityEngine; /// /// 鼠标点击外部栅栏门和内部栅栏门开 /// 需要挂载到玩家上 /// public class RotationOfDoor : MonoBehaviour { [Header("场景外层的门")] /// /// 外层的门 /// public Transform Outerdoor; [Header("场景内层的门")] /// /// 内层的门 /// public Transform Inneredoor; [Header("栅栏内部碰撞")] /// /// 栅栏内部碰撞 /// public GameObject AutomaticdoorclosingColider; private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool raycast = Physics.Raycast(ray, out hit); if (raycast) { if (hit.collider.gameObject.name == "门") { hit.collider.gameObject.transform.DORotate(new Vector3(0, 0, 0), 3f); } if (hit.collider.gameObject.name == "配电箱围栏_门") { hit.collider.gameObject.transform.DORotate(new Vector3(0, 35, 0), 2f); return; } } } } private void OnTriggerEnter(Collider other) { if (other.name == "GatedoorclosingColider") { Outerdoor.gameObject.transform.DORotate(new Vector3(0, 90, 0), 3f); } if (other.name == "AutomaticdoorclosingColider") { Inneredoor.gameObject.transform.DOLocalRotate(new Vector3(0, -90, 0), 2f); AutomaticdoorclosingColider.GetComponent().enabled = false; } if (other.name == "OutsidethedoorColider") { Inneredoor.gameObject.transform.DOLocalRotate(new Vector3(0, -90, 0), 2f); AutomaticdoorclosingColider.GetComponent().enabled = true; } } }