Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/SoundBirdPuzzleSection/soundBird_FlyingBehaviour.cs
Damian 52139cbe64 Flying Bird Puzzle section Complete.
Finished with the logic of the flying bird step.
2025-09-26 15:12:18 +02:00

83 lines
2.2 KiB
C#

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;
private StateMachine stateMachine;
private Animator animator;
private TweenBase objectTween;
//private Coroutine cooldownCoroutine;
public Vector3 midFlightPosition;
private float lastX;
private bool facingRight = true;
void Awake()
{
stateMachine = GetComponentInParent<StateMachine>();
animator = GetComponentInParent<Animator>();
}
private void OnEnable()
{
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.Loop, HandleTweenStarted, HandleTweenFinished);
//cooldownCoroutine = StartCoroutine(CooldownTimer());
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()
{
}
/*private System.Collections.IEnumerator CooldownTimer()
{
yield return new WaitForSeconds(cooldownTime);
midFlightPosition = SoundBirdObject.position;
objectTween.Cancel();
stateMachine.ChangeState("SoundBirdLanding");
}*/
public void StartLanding()
{
midFlightPosition = SoundBirdObject.position;
if (objectTween != null)
{
objectTween.Cancel();
}
stateMachine.ChangeState("SoundBirdLanding");
}
void HandleTweenStarted() { }
void HandleTweenFinished() { }
}