159 lines
4.0 KiB
C#
159 lines
4.0 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Fieldobservation : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 玩家相机
|
|
/// </summary>
|
|
public Camera Camera;
|
|
|
|
/// <summary>
|
|
/// 警告按钮
|
|
/// </summary>
|
|
public Button ExclamationPointBtn;
|
|
|
|
/// <summary>
|
|
/// 封印动画
|
|
/// </summary>
|
|
public SkinnedMeshRenderer SkinnedMeshRenderer;
|
|
|
|
bool isclick;
|
|
|
|
/// <summary>
|
|
/// 上下梯子按钮
|
|
/// </summary>
|
|
public Button UpladderBtn;
|
|
public Button DownladderBtn;
|
|
|
|
/// <summary>
|
|
/// 上梯子后坐标
|
|
/// </summary>
|
|
public Transform UptheladderPos;
|
|
|
|
/// <summary>
|
|
/// 梯子点位
|
|
/// </summary>
|
|
public Transform LadderPos;
|
|
|
|
/// <summary>
|
|
/// 变电箱门锁
|
|
/// </summary>
|
|
public Transform Doorlock;
|
|
|
|
/// <summary>
|
|
/// 变电箱左门
|
|
/// </summary>
|
|
public Transform DoorOfCabinet;
|
|
|
|
/// <summary>
|
|
/// 打开封印
|
|
/// </summary>
|
|
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);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 打开封印动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 柜门先后动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//IEnumerator OpenDoor()
|
|
//{
|
|
// Doorlock069.DOLocalRotate(new Vector3(150, 0, 0), 1f);
|
|
// yield return new WaitForSeconds(2f);
|
|
// LeftDoor.DOLocalRotate(new Vector3(150, 0, 0), 2f);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 用户触发
|
|
/// </summary>
|
|
/// <param name="other"></param>
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.name == "LadderPos")
|
|
{
|
|
UpladderBtn.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用户离开npc警告按钮消失
|
|
/// </summary>
|
|
/// <param name="other"></param>
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.name == "Man_stand")
|
|
{
|
|
ExclamationPointBtn.gameObject.SetActive(false);
|
|
}
|
|
if (other.name == "LadderPos")
|
|
{
|
|
UpladderBtn.gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|
|
}
|