2025-11-05 13:48:25 +01:00
|
|
|
using Core.SaveLoad;
|
2025-09-24 17:24:51 +02:00
|
|
|
using Pixelplacement;
|
|
|
|
|
using Pixelplacement.TweenSystem;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class soundBird_FlyingBehaviour : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Spline FlightSpline;
|
|
|
|
|
public Transform SoundBirdObject;
|
|
|
|
|
public float flightDuration;
|
|
|
|
|
public float flightDelay;
|
|
|
|
|
public float cooldownTime;
|
|
|
|
|
|
2025-11-05 13:48:25 +01:00
|
|
|
private AppleMachine stateMachine;
|
2025-09-24 17:24:51 +02:00
|
|
|
private Animator animator;
|
|
|
|
|
private TweenBase objectTween;
|
2025-09-26 15:12:18 +02:00
|
|
|
//private Coroutine cooldownCoroutine;
|
2025-09-24 17:24:51 +02:00
|
|
|
public Vector3 midFlightPosition;
|
|
|
|
|
|
|
|
|
|
private float lastX;
|
|
|
|
|
private bool facingRight = true;
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
2025-11-05 13:48:25 +01:00
|
|
|
stateMachine = GetComponentInParent<AppleMachine>();
|
2025-09-24 17:24:51 +02:00
|
|
|
animator = GetComponentInParent<Animator>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.Loop, HandleTweenStarted, HandleTweenFinished);
|
2025-09-26 15:12:18 +02:00
|
|
|
//cooldownCoroutine = StartCoroutine(CooldownTimer());
|
2025-09-24 17:24:51 +02:00
|
|
|
lastX = SoundBirdObject.position.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
float currentX = SoundBirdObject.position.x;
|
|
|
|
|
if (currentX > lastX && !facingRight)
|
|
|
|
|
{
|
|
|
|
|
Flip(true);
|
|
|
|
|
}
|
|
|
|
|
else if (currentX < lastX && facingRight)
|
|
|
|
|
{
|
|
|
|
|
Flip(false);
|
|
|
|
|
}
|
|
|
|
|
lastX = currentX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Flip(bool faceRight)
|
|
|
|
|
{
|
|
|
|
|
Vector3 scale = SoundBirdObject.localScale;
|
|
|
|
|
scale.x = Mathf.Abs(scale.x) * (faceRight ? 1 : -1);
|
|
|
|
|
SoundBirdObject.localScale = scale;
|
|
|
|
|
facingRight = faceRight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 15:12:18 +02:00
|
|
|
/*private System.Collections.IEnumerator CooldownTimer()
|
2025-09-24 17:24:51 +02:00
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(cooldownTime);
|
|
|
|
|
midFlightPosition = SoundBirdObject.position;
|
|
|
|
|
objectTween.Cancel();
|
|
|
|
|
stateMachine.ChangeState("SoundBirdLanding");
|
2025-09-26 15:12:18 +02:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public void StartLanding()
|
|
|
|
|
{
|
|
|
|
|
midFlightPosition = SoundBirdObject.position;
|
|
|
|
|
if (objectTween != null)
|
|
|
|
|
{
|
|
|
|
|
objectTween.Cancel();
|
|
|
|
|
}
|
|
|
|
|
stateMachine.ChangeState("SoundBirdLanding");
|
2025-09-24 17:24:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleTweenStarted() { }
|
|
|
|
|
void HandleTweenFinished() { }
|
|
|
|
|
}
|