Flying Bird Puzzle section Complete.

Finished with the logic of the flying bird step.
This commit is contained in:
2025-09-26 15:12:18 +02:00
parent 88e630cbe7
commit 52139cbe64
16 changed files with 9688 additions and 507 deletions

View File

@@ -8,6 +8,7 @@ public class SoundGenerator : MonoBehaviour
[SerializeField] private AudioClip enterSound;
[SerializeField] private AudioSource audioSource;
[SerializeField] private StateMachine soundBirdSMRef;
[SerializeField] private soundBird_CanFly soundbirdHearingCheck;
private bool playerInside = false;
private SpriteRenderer spriteRenderer;
@@ -35,12 +36,11 @@ public class SoundGenerator : MonoBehaviour
{
audioSource.PlayOneShot(enterSound);
}
if (soundBirdSMRef != null && soundBirdSMRef.currentState.name == "SoundBird")
if (soundBirdSMRef != null && soundBirdSMRef.currentState.name == "SoundBird" && soundbirdHearingCheck.canFly == true)
{
soundBirdSMRef.ChangeState("SoundBirdTakeoff"); // Replace with your actual method/state
soundBirdSMRef.ChangeState("SoundBirdTakeoff");
}
// Play sound and change animation/state here if needed
}
}
@@ -54,7 +54,6 @@ public class SoundGenerator : MonoBehaviour
{
spriteRenderer.sprite = exitSprite;
}
// Reset animation/state here if needed
}
}
}

View File

@@ -1,38 +1,31 @@
using UnityEngine;
using Unity.Cinemachine;
using System.Collections;
using Pixelplacement;
public class cameraSwitcher : MonoBehaviour
{
[SerializeField] private CinemachineCamera virtualCamera;
[SerializeField] private float zoomedFOV = 30f;
[SerializeField] private float normalFOV = 40f;
[SerializeField] private Vector3 zoomedOffset = new Vector3(0, 2, -10);
[SerializeField] private Vector3 normalOffset = new Vector3(0, 5, -10);
[SerializeField] private CinemachineConfiner2D confiner2D;
[SerializeField] private float zoomOutOrthoSize = 27f;
[SerializeField] private float normalOrthoSize = 20f;
[SerializeField] private float transitionDuration = 0.5f; // Duration of the transition
[SerializeField] private soundBird_FlyingBehaviour flyingBehaviour;
[SerializeField] private StateMachine birdStateMachine;
private int playerInsideCount = 0;
//private CinemachineTransposer transposer;
private void Start()
{
/* if (virtualCamera != null)
{
transposer = virtualCamera.GetCinemachineComponent<CinemachineTransposer>();
}*/
}
private Coroutine zoomCoroutine;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerInsideCount++;
/*if (playerInsideCount == 1 && virtualCamera != null)
if (playerInsideCount == 1 && virtualCamera != null)
{
// Adjust FOV
virtualCamera.m_Lens.FieldOfView = zoomedFOV;
// Adjust follow distance (offset)
if (transposer != null)
transposer.m_FollowOffset = zoomedOffset;
}*/
if (zoomCoroutine != null) StopCoroutine(zoomCoroutine);
zoomCoroutine = StartCoroutine(SmoothOrthoSize(virtualCamera, zoomOutOrthoSize, transitionDuration));
}
}
}
@@ -41,14 +34,35 @@ public class cameraSwitcher : MonoBehaviour
if (other.CompareTag("Player"))
{
playerInsideCount--;
/*if (playerInsideCount == 0 && virtualCamera != null)
if (playerInsideCount == 0 && virtualCamera != null)
{
// Restore FOV
virtualCamera.m_Lens.FieldOfView = normalFOV;
// Restore follow distance (offset)
if (transposer != null)
transposer.m_FollowOffset = normalOffset;
}*/
if (zoomCoroutine != null) StopCoroutine(zoomCoroutine);
zoomCoroutine = StartCoroutine(SmoothOrthoSize(virtualCamera, normalOrthoSize, transitionDuration));
// Fix: Check if currentState's name is "SoundBirdFlyAround" and flyingBehaviour is not null
if (birdStateMachine.currentState != null &&
birdStateMachine.currentState.name == "SoundBirdFlyAround" &&
flyingBehaviour != null)
{
flyingBehaviour.StartLanding();
}
}
}
}
private IEnumerator SmoothOrthoSize(CinemachineCamera cam, float targetSize, float duration)
{
float startSize = cam.Lens.OrthographicSize;
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
cam.Lens.OrthographicSize = Mathf.Lerp(startSize, targetSize, elapsed / duration);
yield return null;
}
cam.Lens.OrthographicSize = targetSize;
if (confiner2D != null)
{
confiner2D.InvalidateBoundingShapeCache();
}
}
}

View File

@@ -0,0 +1,23 @@
using UnityEngine;
public class soundBird_CanFly : MonoBehaviour
{
public bool canFly = true;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
public void birdCanHear(bool canhear)
{
if (canhear)
{
canFly = true;
}
else
{
canFly = false;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b6a41511eddc628479b46152f9042034

View File

@@ -13,7 +13,7 @@ public class soundBird_FlyingBehaviour : MonoBehaviour
private StateMachine stateMachine;
private Animator animator;
private TweenBase objectTween;
private Coroutine cooldownCoroutine;
//private Coroutine cooldownCoroutine;
public Vector3 midFlightPosition;
private float lastX;
@@ -28,7 +28,7 @@ public class soundBird_FlyingBehaviour : MonoBehaviour
private void OnEnable()
{
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.Loop, HandleTweenStarted, HandleTweenFinished);
cooldownCoroutine = StartCoroutine(CooldownTimer());
//cooldownCoroutine = StartCoroutine(CooldownTimer());
lastX = SoundBirdObject.position.x;
}
@@ -59,12 +59,22 @@ public class soundBird_FlyingBehaviour : MonoBehaviour
}
private System.Collections.IEnumerator CooldownTimer()
/*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() { }

View File

@@ -29,7 +29,7 @@ public class soundBird_LandingBehaviour1 : MonoBehaviour
{
anchorB.position = flyingBehaviour.midFlightPosition;
}
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseOut, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
// Initialize lastX for flipping logic
if (SoundBirdObject != null)

View File

@@ -1,57 +0,0 @@
using Pixelplacement;
using UnityEngine;
public class soundBird_Spooked_FlyBehaviour : MonoBehaviour
{
public Spline FlightSpline;
public Transform SoundBirdObject;
public float flightDuration;
public float flightDelay;
[Range(0, 1)] public float startPercentage;
private StateMachine stateMachine;
private Animator animator;
[SerializeField] private State stateRef;
void Awake()
{
stateMachine = GetComponentInParent<StateMachine>();
animator = GetComponentInParent<Animator>();
stateRef = GetComponent<State>();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
//initiateTweenSpline();
}
private void OnEnable()
{
Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
}
void HandleTweenStarted()
{
}
void HandleTweenFinished()
{
if (SoundBirdObject != null)
{
//Tween.Stop(SoundBirdObject.GetInstanceID(), Tween.TweenType.Spline); // Stop the spline tween for this object
}
//Debug.Log("Tween finished!");
if (stateMachine != null)
{
//stateMachine.ChangeState("SoundBird"); // Change to the desired state name
}
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 10bb74c0e6993ea428971e8ae0b07ed9

View File

@@ -25,7 +25,7 @@ public class soundBird_TakeOffBehaviour : MonoBehaviour
private void OnEnable()
{
animator.SetBool("isScared", true);
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseLinear, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
objectTween = Tween.Spline(FlightSpline, SoundBirdObject, 0, 1, false, flightDuration, flightDelay, Tween.EaseIn, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
}
void HandleTweenStarted()
{