123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 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<Material> list_material;
- public Vector3 endPos;
- public Vector3 exitPos;
- private Material material;
- private Vector2 offset;
-
- void Start()
- {
- material = this.GetComponent<MeshRenderer>().material;
- offset = Vector2.zero;
-
- }
-
- void Update()
- {
- offset -= Interval;
- material.SetTextureOffset("_MainTex", offset);
- }
-
-
-
-
-
- public void SetRoute( Vector3 endPos, Vector3 exitPos )
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- this.endPos = endPos;
- this.exitPos = exitPos;
-
-
-
-
-
-
- transform.localScale += new Vector3(0, 0, Mathf.Abs( Vector3.Distance(endPos,exitPos) )/20f);
-
- 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<MeshRenderer>().material = list_material[Index];
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- this.endPos = endPos;
- this.exitPos = exitPos;
- Debug.Log("Route " + endPos + " " + exitPos);
-
-
-
-
-
-
- transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(endPos, exitPos)) / 20f);
- 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);
-
- }
-
-
-
-
-
- public void SetMapRoute()
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
-
-
-
-
-
-
-
-
-
-
- material.SetTextureScale("_MainTex", new Vector2(1, 2f));
- }
- public void SetMapRoute( Vector3 endPos , Vector3 exitPos)
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
-
-
-
- material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 0.7f));
-
-
-
-
-
-
-
- }
-
- public Transform A;
- public Transform B;
-
- public void Test()
- {
- SetRoute(A.position, B.position);
- }
-
- }
|