Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/AnneLiseBehaviour.cs

54 lines
1.3 KiB
C#
Raw Normal View History

using UnityEngine;
using System;
using Pathfinding;
2025-09-12 13:57:26 +02:00
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<Animator>();
aiPath = GetComponent<AIPath>();
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");
}
}