So I am working on a game and I need the AI to animate im pretty new to do this im using sebastain lagues speedPercent for the animating and im using blend tree here is the code using
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Patroller : MonoBehaviour
{
public Transform[] waypoints;
public int speed;
public int waypointIndex;
public float dist;
// Start is called before the first frame update
void Start()
{
waypointIndex = 0;
transform.LookAt(waypoints[waypointIndex].position);
}
// Update is called once per frame
void Update()
{
dist = Vector3.Distance(transform.position, waypoints[waypointIndex].position);
if(dist < 1f){
IncreaseIndex();
}
Patrol();
}
void Patrol(){
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
void IncreaseIndex()
{
waypointIndex++;
if(waypointIndex >= waypoints.Length){
waypointIndex = 0;
}
transform.LookAt(waypoints[waypointIndex].position);
}
}