WIP Butterfly can be set free, now only missing forcing the couple to look.
This commit is contained in:
@@ -4,52 +4,50 @@ using Core.SaveLoad;
|
||||
|
||||
public class ButterFlyBehaviour : MonoBehaviour
|
||||
{
|
||||
public AppleMachine butterStateMachine;
|
||||
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;
|
||||
private Animator butterflyAnimator;
|
||||
|
||||
// Called when entering the butterfly flight state
|
||||
public void OnEnterState()
|
||||
public void OnEnable()
|
||||
{
|
||||
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)
|
||||
if (butterflyObject != null )
|
||||
{
|
||||
targetPercentage = 1f;
|
||||
duration = flightDuration * (1f - startPercentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetPercentage = 0f;
|
||||
duration = flightDuration * startPercentage;
|
||||
butterflyAnimator = butterflyObject.GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
butterflyAnimator.SetTrigger("BrokeOut");
|
||||
|
||||
Tween.Spline(
|
||||
butterflightSpline,
|
||||
butterflyObject,
|
||||
startPercentage,
|
||||
targetPercentage,
|
||||
0,
|
||||
1,
|
||||
false,
|
||||
duration,
|
||||
flightDuration,
|
||||
flightDelay,
|
||||
Tween.EaseInOut,
|
||||
Tween.LoopType.None
|
||||
Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished
|
||||
);
|
||||
}
|
||||
public void HandleTweenStarted()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HandleTweenFinished()
|
||||
{
|
||||
butterStateMachine.ChangeState("Free");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user