ShanxiKnowledgeBase/SXElectricityFaultA&E/Assets/taoruiqi/Script/RotationOfDoor.cs

71 lines
2.0 KiB
C#

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
/// <summary>
/// 鼠标点击外部栅栏门和内部栅栏门开
/// 需要挂载到玩家上
/// </summary>
public class RotationOfDoor : MonoBehaviour
{
[Header("场景外层的门")]
/// <summary>
/// 外层的门
/// </summary>
public Transform Outerdoor;
[Header("场景内层的门")]
/// <summary>
/// 内层的门
/// </summary>
public Transform Inneredoor;
[Header("栅栏内部碰撞")]
/// <summary>
/// 栅栏内部碰撞
/// </summary>
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<BoxCollider>().enabled = false;
}
if (other.name == "OutsidethedoorColider")
{
Inneredoor.gameObject.transform.DOLocalRotate(new Vector3(0, -90, 0), 2f);
AutomaticdoorclosingColider.GetComponent<BoxCollider>().enabled = true;
}
}
}