22 lines
623 B
C#
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++;
|
|
}
|
|
}
|
|
}
|
|
}
|