56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
|
|
using Pixelplacement;
|
||
|
|
using UnityEngine;
|
||
|
|
using Core.SaveLoad;
|
||
|
|
|
||
|
|
public class ButterFlyBehaviour : MonoBehaviour
|
||
|
|
{
|
||
|
|
public Spline butterflightSpline;
|
||
|
|
public Transform butterflyObject;
|
||
|
|
public float flightDuration = 2f;
|
||
|
|
public float flightDelay = 0f;
|
||
|
|
[Range(0, 1)] public float startPercentage = 0f;
|
||
|
|
|
||
|
|
private const float AnchorThreshold = 0.05f;
|
||
|
|
|
||
|
|
// Called when entering the butterfly flight state
|
||
|
|
public void OnEnterState()
|
||
|
|
{
|
||
|
|
if (butterflightSpline == null || butterflyObject == null)
|
||
|
|
{
|
||
|
|
Debug.LogWarning("ButterFlyBehaviour: Missing spline or butterfly object reference.");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
butterflyObject.position = butterflightSpline.GetPosition(startPercentage);
|
||
|
|
|
||
|
|
float distanceToStart = Mathf.Abs(startPercentage - 0f);
|
||
|
|
float distanceToEnd = Mathf.Abs(startPercentage - 1f);
|
||
|
|
|
||
|
|
float targetPercentage;
|
||
|
|
float duration;
|
||
|
|
|
||
|
|
if (distanceToStart < distanceToEnd)
|
||
|
|
{
|
||
|
|
targetPercentage = 1f;
|
||
|
|
duration = flightDuration * (1f - startPercentage);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
targetPercentage = 0f;
|
||
|
|
duration = flightDuration * startPercentage;
|
||
|
|
}
|
||
|
|
|
||
|
|
Tween.Spline(
|
||
|
|
butterflightSpline,
|
||
|
|
butterflyObject,
|
||
|
|
startPercentage,
|
||
|
|
targetPercentage,
|
||
|
|
false,
|
||
|
|
duration,
|
||
|
|
flightDelay,
|
||
|
|
Tween.EaseInOut,
|
||
|
|
Tween.LoopType.None
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|