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(); animator = GetComponentInParent(); } 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() { } }