using UnityEngine; using System; using Pathfinding; public class AnneLiseBehaviour : MonoBehaviour { [SerializeField] public float moveSpeed; private Animator animator; private AIPath aiPath; private bool hasArrived = false; // Flag to prevent repeated triggering private void Awake() { animator = GetComponentInChildren(); aiPath = GetComponent(); if (aiPath != null) { aiPath.maxSpeed = moveSpeed; } } public void GotoSpot(GameObject lurespot) { if (aiPath == null) return; aiPath.destination = lurespot.transform.position; aiPath.canMove = true; aiPath.SearchPath(); hasArrived = false; // Reset flag when a new destination is set } private void Update() { if (aiPath == null || animator == null) return; float currentSpeed = aiPath.velocity.magnitude; animator.SetFloat("speed", currentSpeed); // Only trigger arrival logic once if (!hasArrived && aiPath.reachedDestination && currentSpeed < 0.01f) { hasArrived = true; OnArriveAtSpot(); aiPath.canMove = false; } } private void OnArriveAtSpot() { if (animator != null) animator.SetTrigger("TakePhoto"); } }