2025-09-11 17:03:56 +02:00
|
|
|
using UnityEngine;
|
2025-09-16 15:52:30 +02:00
|
|
|
using System;
|
2025-09-16 18:14:00 +02:00
|
|
|
using Pathfinding;
|
2025-09-11 17:03:56 +02:00
|
|
|
|
2025-09-12 13:57:26 +02:00
|
|
|
public class AnneLiseBehaviour : MonoBehaviour
|
2025-09-11 17:03:56 +02:00
|
|
|
{
|
2025-09-16 15:52:30 +02:00
|
|
|
[SerializeField] public float moveSpeed;
|
2025-09-16 18:14:00 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-16 15:52:30 +02:00
|
|
|
|
|
|
|
|
public void GotoSpot(GameObject lurespot)
|
2025-09-11 17:03:56 +02:00
|
|
|
{
|
2025-09-16 18:14:00 +02:00
|
|
|
if (aiPath == null) return;
|
2025-09-11 17:03:56 +02:00
|
|
|
|
2025-09-16 18:14:00 +02:00
|
|
|
aiPath.destination = lurespot.transform.position;
|
|
|
|
|
aiPath.canMove = true;
|
|
|
|
|
aiPath.SearchPath();
|
|
|
|
|
hasArrived = false; // Reset flag when a new destination is set
|
2025-09-16 15:52:30 +02:00
|
|
|
}
|
2025-09-16 18:14:00 +02:00
|
|
|
|
|
|
|
|
private void Update()
|
2025-09-11 17:03:56 +02:00
|
|
|
{
|
2025-09-16 18:14:00 +02:00
|
|
|
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)
|
2025-09-16 15:52:30 +02:00
|
|
|
{
|
2025-09-16 18:14:00 +02:00
|
|
|
hasArrived = true;
|
|
|
|
|
OnArriveAtSpot();
|
|
|
|
|
aiPath.canMove = false;
|
2025-09-16 15:52:30 +02:00
|
|
|
}
|
2025-09-16 18:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnArriveAtSpot()
|
|
|
|
|
{
|
|
|
|
|
if (animator != null)
|
|
|
|
|
animator.SetTrigger("TakePhoto");
|
2025-09-11 17:03:56 +02:00
|
|
|
}
|
|
|
|
|
}
|