AnneLise moved to the spot, still trying to make her interactable then
This commit is contained in:
@@ -1,16 +1,39 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
public class AnneLiseBehaviour : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
// 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;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user