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

40 lines
1.3 KiB
C#

using UnityEngine;
using System.Collections;
using System;
public class AnneLiseBehaviour : MonoBehaviour
{
// Movement speed of AnneLise
[SerializeField] public float moveSpeed;
// Coroutine reference to manage movement
private Coroutine moveCoroutine;
// Event triggered when AnneLise arrives at the target spot
public event Action OnArrivedAtSpot;
// Method to initiate movement to the specified lure spot
public void GotoSpot(GameObject lurespot)
{
if (moveCoroutine != null)
StopCoroutine(moveCoroutine);
moveCoroutine = StartCoroutine(MoveToPosition(lurespot.transform.position));
}
// Coroutine to move AnneLise to the target position
private IEnumerator MoveToPosition(Vector3 targetPosition)
{
while (Vector3.Distance(transform.position, targetPosition) > 0.05f)
{
transform.position = Vector3.MoveTowards(
transform.position,
targetPosition,
moveSpeed * Time.deltaTime
);
yield return null;
}
transform.position = targetPosition; // Snap to exact position at the end
moveCoroutine = null;
// Trigger the arrival event
OnArrivedAtSpot?.Invoke();
}
}