using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 绝缘胶带 /// public class AdhesiveTape : MonoBehaviour { /// /// 绝缘胶带 /// public GameObject TapeOBJ; /// /// 电线前段胶带 /// public Material TapeMar; /// /// 电线碰撞 /// public BoxCollider TapeMarCol; // Start is called before the first frame update void Start() { Init(); } void Init() { TapeMar.SetFloat("_step_p1", 0); TapeMar.SetFloat("_step_p2", 0); TapeMar.SetFloat("_step_p3", 0); TapeMar.SetFloat("_step_p4", 0); TapeMar.SetFloat("_step_p5", 0); TapeMar.SetFloat("_step_p6", 0); //TapeMar.SetFloat("_step_p1", 1); } // Update is called once per frame 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 == "pCylinder170") { StartCoroutine(Tape()); } } } } /// /// 电线缠胶带 /// /// IEnumerator Tape() { TapeOBJ.gameObject.transform.DOLocalMove(new Vector3(3.1215f, 2.1383f, -1.3484f),1f); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p1", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p2", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p3", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p4", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p5", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p6", 1); yield return new WaitForSeconds(1f); StartCoroutine(TapeBack()); } /// /// 胶带返回动画 /// /// IEnumerator TapeBack() { TapeOBJ.transform.DOLocalMove(new Vector3(3.179443f, 1.790938f, -1.107346f),1f); TapeMarCol.enabled = false; yield return new WaitForSeconds(1f); } }