using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestRoute : MonoBehaviour { public Vector2 Interval = new Vector2(0, -0.02f); /// /// 旋转方向 /// public Transform point; public List list_material; public Vector3 endPos; public Vector3 exitPos; public Transform A; public Transform B; private Material material; private Vector2 offset; void Start() { material = this.GetComponent().material; offset = Vector2.zero; // Test(); } // Update is called once per frame void Update() { offset -= Interval; material.SetTextureOffset("_MainTex", offset); } /// /// 设置Route 位置 长度 朝向 旋转 /// /// /// public void SetRoute( Vector3 endPos, Vector3 exitPos ) { if (material == null) material = this.GetComponent().material; this.endPos = endPos; this.exitPos = exitPos; transform.localScale += new Vector3(0, 0, Mathf.Abs( Vector3.Distance(endPos,exitPos) )/12f - (transform.localScale.x * 2)); material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos))*1.5f)); Vector3 pos = endPos + (exitPos - endPos).normalized * (Vector3.Distance(endPos, exitPos)); transform.position = (exitPos+endPos)/2.0f + new Vector3(0, -2f, 0); Debug.Log("Route " + endPos + " " + exitPos +" "+ transform.position); point.position = endPos + new Vector3(0, transform.position.y, 0); transform.LookAt(point); } public void SetRoute(Vector3 endPos, Vector3 exitPos ,int Index) { this.GetComponent().material = list_material[Index]; if (material == null) material = this.GetComponent().material; this.endPos = endPos; this.exitPos = exitPos; // Debug.Log("Route " + endPos + " " + exitPos); transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(endPos, exitPos))/12 -(transform.localScale.x*2)); material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 1.5f)); Vector3 pos = endPos + (exitPos - endPos).normalized * (Vector3.Distance(endPos, exitPos)); transform.position = (exitPos + endPos) / 2.0f + new Vector3(0, -2f, 0); point.position = endPos + new Vector3(0, transform.position.y, 0); transform.LookAt(point); } /// /// 3DMapRoute /// /// /// public void SetMapRoute() { if (material == null) material = this.GetComponent().material; material.SetTextureScale("_MainTex", new Vector2(1, 2f)); } public void SetMapRoute( Vector3 endPos , Vector3 exitPos) { if (material == null) material = this.GetComponent().material; material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 0.7f)); } public void Test() { SetRoute(A.position, B.position); } }