Question by
Mark-Mark · Mar 16, 2021 at 05:23 PM ·
animatornavmeshnavmeshagentanimator controller
Animator scripting not working as expected,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NPCpatrol : MonoBehaviour
{
public Transform[] points; // this list is compromised of 3 "points"
private int destPoint = 0;
private NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
GotoNextPoint();
}
public Animator anim;
//public Transform dots;
void GotoNextPoint()
{
//float dist = Vector3.Distance(dots.position, transform.position);
//this was my first try, but this didin't work and i pasted it into Uptade()
/*if ( points.Length == 2f)
{
anim = GetComponent<Animator>();
// anim.SetTrigger("trigger");
//anim.Play("trigger", 1);
anim.SetBool("trigger", true);
return;
}
anim.SetBool("trigger", false);*/
agent.destination = points[destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
// Update is called once per frame
void Update()
{ //this also doesen't work
if (points.Length <= 2f)
{
anim = GetComponent<Animator>();
// anim.SetTrigger("trigger");
//anim.Play("trigger", 1);
anim.SetBool("trigger", true);
}
else
{
anim.SetBool("trigger", false);
}
if (!agent.pathPending && agent.remainingDistance < 0.5f)
{
GotoNextPoint();
}
}
}
I'm trying to toggle "trigger" if points.length <= 2f but nothing will happen once gameobject gets close to points? i have three "points" or Waypoints and one agent, that's the navmesh for. i'm probably doing something wrong, but neither i know how to fix it nor how to search the error. please help.,
Comment