Yes, I did. The path also learned to count. But in the paid version of the library there are functions with which it would be better. Now I’m working on the step strip. Here is the script I am working on.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Pathfinding
{
public class AidWar : VersionedMonoBehaviour
{
AILerp ai2;
Seeker Seeek;
LineRenderer lin;
GameObject obect;
public GameObject obecty;
public Transform pytKon;
bool warlin = false;
bool warVkl = false;
GameObject obect2;
List<Vector3> buffer = new List<Vector3>();
Vector3 tchk = new Vector3();
bool mysh = false;
bool mysh2 = false;
Vector3 hithit = new Vector3();
Path pp;
GridGraph grid;
GridGraph segment;
List<GraphNode> spgrid = new List<GraphNode>();
GraphNode posPer;
public Image poloskaVerh2;
public Image poloskaVerh1;
Transform prom;
float dist;
float distNach;
float poloska;
float poloska2;
float polS;
float koef;
void OnEnable()
{
Seeek = GetComponent<Seeker>();
ai2 = GetComponent<AILerp>();
ai2.enableRotation = false;
ai2.canMove = false;
ai2.canSearch = true;
lin = GetComponent<LineRenderer>();
warVkl = true;
GetComponent<aid>().enabled=false;
int tt = GetComponent<Outfit>().Personag.speed;
if (tt==30)
{
dist = 11;
distNach = 11;
koef = 21.4f;
}
else if (tt==40)
{
dist = 14;
distNach = 14;
koef = 16f;
}
print(dist);
poloska = 214;
poloska2 = 214;
poloskaVerh2.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
214);
poloskaVerh2.rectTransform.ForceUpdateRectTransforms();
//grid = AstarPath.active.data.gridGraph;
//spgrid = PathUtilities.BFS(posPer, 10);
//List<Vector3> v3position = new List<Vector3>(spgrid.Count);
//for (int i=0; i< spgrid.Count; i++)
//{
// v3position.Add ((Vector3)spgrid[i].position);
// Instantiate(pytKon, new Vector3(v3position[i].x,10,v3position[i].z), Quaternion.Euler(90, 0, 0));
//}
}
void OnDisable()
{
warVkl = false;
buffer.Clear();
lin.enabled = false;
Destroy(obect);
Destroy(obect2);
ai2.canSearch = false;
ai2.SetPath(null);
ai2.canMove = true;
GetComponent<aid>().enabled = true;
}
void Update()
{
var dir = ai2.velocity;
dir.y = 0;
if (dir != Vector3.zero) ai2.rotation = Quaternion.LookRotation(dir);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (prom != null)
{
GameObject promOb = prom.GetChild(1).gameObject;
promOb.SetActive(false);
prom = null;
}
if (!EventSystem.current.IsPointerOverGameObject() && Physics.Raycast(ray, out hit, 1000))
{
var gytok = hit.transform;
if (gytok.CompareTag("Unit"))
{
GameObject promOb = gytok.GetChild(1).gameObject;
if (promOb != null)
{
promOb.SetActive(true);
}
prom = gytok;
}
}
if (Physics.Raycast(ray, out hit, 1000) && hit.collider.gameObject.tag == "zemlya")
{
if (warVkl == true)
{
hithit = hit.point;
GraphNode nodeS2 = AstarPath.active.GetNearest(hit.point).node;
if (nodeS2.Walkable == true)
{
ai2.destination = hithit;
ai2.SearchPath();
}
buffer = new List<Vector3>();
if (ai2.remainingDistance>=1 && ai2.remainingDistance < dist )
{
// print(ai2.remainingDistance);
lin.enabled = true;
if (ai2.remainingDistance <= dist - 1)
{
poloskaVerh2.GetComponent<Image>().color = new Color(0.5333334f, 0.8862745f, 0.1882353f,1);
polS = poloska - (ai2.remainingDistance - 0.5f) * koef;
poloskaVerh2.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
polS);
poloskaVerh2.rectTransform.ForceUpdateRectTransforms();
}
else if (ai2.remainingDistance < dist)
{
polS = poloska - (ai2.remainingDistance - 0.5f) * koef;
poloskaVerh2.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
polS);
poloskaVerh2.rectTransform.ForceUpdateRectTransforms();
poloskaVerh2.GetComponent<Image>().color =
Color.Lerp(Color.green, Color.white, Mathf.PingPong(Time.unscaledTime*5, 1));
}
ai2.GetRemainingPath(buffer, out bool stale);
lin.positionCount = buffer.Count;
lin.SetPositions(buffer.ToArray());
tchk = new Vector3(buffer.Last().x, 10, buffer.Last().z);
if (warlin == false)
{
obect = Instantiate(obecty, tchk, Quaternion.Euler(90, 0, 0));
Destroy(obect2);
warlin = true;
}
else
{
obect2 = Instantiate(obecty, tchk, Quaternion.Euler(90, 0, 0));
Destroy(obect);
warlin = false;
}
mysh2 = false;
}
else
{
buffer.Clear();
lin.enabled = false;
Destroy(obect);
Destroy(obect2);
mysh2 = true;
}
}
}
else if (hit.collider.gameObject == ai2.gameObject && mysh == false)
{
lin.enabled = false;
ai2.SetPath(null);
Destroy(obect);
Destroy(obect2);
poloskaVerh2.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
poloska);
poloskaVerh2.rectTransform.ForceUpdateRectTransforms();
}
if (!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0))
{
if (mysh == false &&mysh2==false)
{
WarRegim.hd_nt = true;
mysh = true;
// poloskaVerh1.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
//poloska - (ai2.remainingDistance+1) * 21.4f);
// poloskaVerh1.rectTransform.ForceUpdateRectTransforms();
dist =dist-ai2.remainingDistance; //(ai2.remainingDistance-0.5f) * 21.4f
if (dist >= 1) poloska = polS;
else poloska=0;
poloskaVerh2.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
poloska);
poloskaVerh2.rectTransform.ForceUpdateRectTransforms();
print(dist);
float vremya = dist/ai2.speed ;
warVkl = false;
lin.enabled = false;
Destroy(obect);
Destroy(obect2);
obect2 = Instantiate(pytKon.gameObject, tchk, Quaternion.Euler(90, 0, 0));
ai2.canMove = true;
// print(vremya);
}
}
if (ai2.reachedDestination)
{
ai2.SetPath(null);
ai2.canMove = false;
Destroy(obect2);
warVkl = true;
mysh = false;
WarRegim.hd_nt = false;
}
}
}
}
Here’s what came out.
By blinking, I masked what I did not succeed.
Now I’m trying to make the second green bar decrease as the character travels the path.
It probably must be done through the coroutine? I would be grateful if I could tell the formulas and functions through which this can be done. The length of the green strip, the length of the path and the speed of the character are known.