animation is linked to speed slider

This commit is contained in:
Simon O'Shea
2023-08-09 14:23:24 -04:00
parent b56131d7fa
commit 8181a3426a
2 changed files with 17 additions and 6 deletions
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class CellMesh : MonoBehaviour
{
@@ -11,6 +12,8 @@ public class CellMesh : MonoBehaviour
Vector2[] m_uv;
int[] m_triangles;
Stack<Node> animateData;
private void Awake()
{
mesh = new Mesh();
@@ -78,24 +81,32 @@ public class CellMesh : MonoBehaviour
mesh.triangles = triangles;
}
public void Animate(Stack<Node> result)
{
int count = result.Count;
animateData = result;
StartCoroutine("AnimateGrid");
}
IEnumerator AnimateGrid()
{
int count = animateData.Count;
for (int i = 0; i < count; i++)
{
Node n = result.Pop();
Node n = animateData.Pop();
//Debug.Log("Agent at: " + n.agent.x + ", " + n.agent.y);
Debug.Log(n.lastMove);
grid.SetValue(n.agent.x, n.agent.y, 3);
//grid.SetValue(n.parent.agent.x, n.parent.agent.y, 0);
grid.SetValue(n.parent.agent.x, n.parent.agent.y, 0);
yield return new WaitForSeconds(nMain.speed);
UpdateCellVisual();
}
}
void Start()
{