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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
13
Assets/Scripts/DamianExperiments/ButterFlyState.cs
Normal file
13
Assets/Scripts/DamianExperiments/ButterFlyState.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Core.SaveLoad;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
|
||||
public class ButterFlyState : AppleMachine
|
||||
{
|
||||
|
||||
public void stateSwitch(string StateName)
|
||||
{
|
||||
Logging.Debug("State Switch to: " + StateName);
|
||||
ChangeState(StateName);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/DamianExperiments/ButterFlyState.cs.meta
Normal file
2
Assets/Scripts/DamianExperiments/ButterFlyState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b889d915f28f8ac4ebeb12013bcaa4ce
|
||||
19
Assets/Scripts/DamianExperiments/ButterflyFreeBehaviour.cs
Normal file
19
Assets/Scripts/DamianExperiments/ButterflyFreeBehaviour.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Pixelplacement;
|
||||
using UnityEngine;
|
||||
using Core.SaveLoad;
|
||||
public class ButterflyFreeBehaviour : MonoBehaviour
|
||||
{
|
||||
public GameObject butterflyRef;
|
||||
private Animator butterflyAnimator;
|
||||
public void OnEnable()
|
||||
{
|
||||
if (butterflyRef != null)
|
||||
{
|
||||
butterflyAnimator = butterflyRef.GetComponentInChildren<Animator>();
|
||||
}
|
||||
butterflyAnimator.SetTrigger("IsFree");
|
||||
|
||||
Debug.Log("ButterflyFreeBehaviour enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6821f70f6ac4b85418b15ce068ddc6da
|
||||
Reference in New Issue
Block a user