Flying Bird Puzzle section Complete.
Finished with the logic of the flying bird step.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user