using System.Collections; using System.Collections.Generic; using UnityEngine; public class Route : MonoBehaviour { private Vector2 Interval = new Vector2(0, 0.02f); public List ListLineMat; /// /// 旋转方向 /// public Transform Point; public Vector3 EndPos; public Vector3 StartPos; private Material material; private Vector2 offset; void Start() { material = this.GetComponent().material; offset = Vector2.zero; } void Update() { offset -= Interval; material.SetTextureOffset("_MainTex", offset); } /// /// 设置Route 位置 长度 朝向 旋转 /// /// /// public void SetRoute(Vector3 endPos, Vector3 startPos, int Index) { this.GetComponent().material = ListLineMat[Index]; if (material == null) material = this.GetComponent().material; this.EndPos = endPos; this.StartPos = startPos; // Debug.Log("Route " + endPos + " " + exitPos); transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) / 12 - (transform.localScale.x * 2)); material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) * 1.5f)); transform.localPosition = (StartPos + EndPos) / 2.0f; Point.localPosition = StartPos + new Vector3(0, transform.localPosition.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)); } }