12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Route : MonoBehaviour
- {
- private Vector2 Interval = new Vector2(0, 0.05f);
- public List<Material> ListLineMat;
-
-
-
- public Transform Point;
- public Vector3 EndPos;
- public Vector3 StartPos;
- public Material material_High;
- private Material material;
- private MeshRenderer meshRenderer;
- private Vector2 offset;
- void Start()
- {
- meshRenderer = this.GetComponent<MeshRenderer>();
- material = meshRenderer.material;
- offset = Vector2.zero;
- StartCoroutine(SetOffset());
- }
- void Update()
- {
-
- }
- private IEnumerator SetOffset()
- {
- while(true)
- {
- yield return new WaitForSeconds(0.04f);
- offset -= Interval;
- material.SetTextureOffset("_MainTex", offset);
- material_High.SetTextureOffset("_MainTex", offset);
- }
- }
- public void setHighLight( bool isHigh)
- {
-
- if (isHigh)
- meshRenderer.material = material_High;
- else
- meshRenderer.material = material;
-
- }
-
-
-
-
-
- public void SetRoute(Vector3 endPos, Vector3 startPos, int Index)
- {
- this.GetComponent<MeshRenderer>().material = ListLineMat[Index];
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- this.EndPos = endPos;
- this.StartPos = startPos;
-
- 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);
- }
-
-
-
-
-
- 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));
- }
- }
|