using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 剥线钳功能 /// public class Pliers : MonoBehaviour { /// /// 剥线钳物体 /// public GameObject PliersObj; /// /// 钳线动画 /// public Animation PliersAni; /// /// 封印动画 /// public SkinnedMeshRenderer SkinnedMeshRenderer; /// /// 变电箱门锁 /// public Transform Doorlock; /// /// 变电箱左门 /// public Transform DoorOfCabinet; /// /// 是否选取/在手上 /// bool inhand; void Start() { //PliersAni.Play("线钳"); } void Update() { if (!inhand) { 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(PliersIE()); Debug.Log(hit.collider.gameObject.name); } } } } if (Input.GetKeyDown(KeyCode.E)) { PliersAni.Play("钳线"); } } /// /// 剥线钳动画 /// /// IEnumerator PliersIE() { PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.0849f, 2.7143f, 163.5919f),1f); yield return new WaitForSeconds(2f); PliersAni.Play("钳线"); yield return new WaitForSeconds(1); StartCoroutine(OpenLock()); } /// /// 打开封印动画 /// /// IEnumerator OpenLock() { for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.01f); SkinnedMeshRenderer.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(1f); SkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.637f, 0.12f, -0.015f), 1f); yield return new WaitForSeconds(2f); 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); } }