55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using Pixelplacement;
|
|
using UnityEngine;
|
|
using Core.SaveLoad;
|
|
|
|
public class ButterFlyBehaviour : MonoBehaviour
|
|
{
|
|
public AppleMachine butterStateMachine;
|
|
public Spline butterflightSpline;
|
|
public Transform butterflyObject;
|
|
public float flightDuration = 2f;
|
|
public float flightDelay = 0f;
|
|
|
|
private const float AnchorThreshold = 0.05f;
|
|
private Animator butterflyAnimator;
|
|
|
|
// Called when entering the butterfly flight state
|
|
public void OnEnable()
|
|
{
|
|
if (butterflightSpline == null || butterflyObject == null)
|
|
{
|
|
Debug.LogWarning("ButterFlyBehaviour: Missing spline or butterfly object reference.");
|
|
return;
|
|
}
|
|
if (butterflyObject != null )
|
|
{
|
|
butterflyAnimator = butterflyObject.GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
butterflyAnimator.SetTrigger("BrokeOut");
|
|
GetComponent<AppleAudioSource>().Play(0);
|
|
|
|
Tween.Spline(
|
|
butterflightSpline,
|
|
butterflyObject,
|
|
0,
|
|
1,
|
|
false,
|
|
flightDuration,
|
|
flightDelay,
|
|
Tween.EaseInOut,
|
|
Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished
|
|
);
|
|
}
|
|
public void HandleTweenStarted()
|
|
{
|
|
|
|
}
|
|
|
|
public void HandleTweenFinished()
|
|
{
|
|
butterStateMachine.ChangeState("Free");
|
|
}
|
|
|
|
}
|