using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 剥线钳功能 /// public class Pliers : MonoBehaviour { /// /// 剥线钳物体 /// public GameObject PliersObj; /// /// 钳线动画 /// public SkinnedMeshRenderer PliersSki; /// /// 封印动画 /// 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("钳线"); //} } float weight; /// /// 剥线钳动画 /// /// IEnumerator PliersIE() { PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.0849f, 2.696f, 163.5919f),1f); yield return new WaitForSeconds(1.5f); PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90,90,0),1.5f); yield return new WaitForSeconds(2f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(1f); 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(0.5f); Doorlock.transform.DOLocalRotate(new Vector3(160, 0, 0), 1f); yield return new WaitForSeconds(1.5f); DoorOfCabinet.transform.DOLocalRotate(new Vector3(-90, 0, 160), 2f); StartCoroutine(PliersBack()); } IEnumerator PliersBack() { PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.05f, 2.386f, 163.028f),1.5f); PliersObj.gameObject.transform.DOLocalRotate(new Vector3(0,90,0),1.5f); yield return new WaitForSeconds(2f); PliersObj.gameObject.SetActive(false); } }