Astar_demo/Assets/PathWalker.cs
2023-11-28 11:29:52 +05:30

22 lines
623 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathWalker : MonoBehaviour
{
public List<Transform> pathNodes = new List<Transform>();
public int curIndex = 0;
void Update(){
if(pathNodes.Count < 2){return;}
if(curIndex < pathNodes.Count){
if(Vector2.Distance(pathNodes[curIndex].position, transform.position) > 0.1f){
//Move Towards node
transform.position += (pathNodes[curIndex].position - transform.position).normalized * Time.deltaTime * 2f;
}else{
curIndex++;
}
}
}
}