Disabled Saves, moved Folders adn renamed Data files, and added a state machine to the cookie puzzle
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using UnityEngine;
|
||||
using Unity.Cinemachine;
|
||||
using System.Collections;
|
||||
using Core.SaveLoad;
|
||||
using Pixelplacement;
|
||||
|
||||
public class cameraSwitcher : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private CinemachineCamera virtualCamera;
|
||||
[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 soundBird_TakeOffBehaviour takeOffBehaviour; // New reference
|
||||
[SerializeField] private AppleMachine birdStateMachine;
|
||||
|
||||
private int playerInsideCount = 0;
|
||||
private Coroutine zoomCoroutine;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
playerInsideCount++;
|
||||
if (playerInsideCount == 1 && virtualCamera != null)
|
||||
{
|
||||
if (zoomCoroutine != null) StopCoroutine(zoomCoroutine);
|
||||
zoomCoroutine = StartCoroutine(SmoothOrthoSize(virtualCamera, zoomOutOrthoSize, transitionDuration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (!gameObject.activeInHierarchy)
|
||||
return;
|
||||
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
playerInsideCount--;
|
||||
if (playerInsideCount == 0 && virtualCamera != null)
|
||||
{
|
||||
if (zoomCoroutine != null) StopCoroutine(zoomCoroutine);
|
||||
zoomCoroutine = StartCoroutine(SmoothOrthoSize(virtualCamera, normalOrthoSize, transitionDuration));
|
||||
if (birdStateMachine.currentState != null)
|
||||
{
|
||||
if (birdStateMachine.currentState.name == "SoundBirdFlyAround" && flyingBehaviour != null)
|
||||
{
|
||||
flyingBehaviour.StartLanding();
|
||||
}
|
||||
else if (birdStateMachine.currentState.name == "SoundBirdTakeoff" && takeOffBehaviour != null)
|
||||
{
|
||||
takeOffBehaviour.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);
|
||||
if (confiner2D != null)
|
||||
{
|
||||
confiner2D.InvalidateBoundingShapeCache();
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
cam.Lens.OrthographicSize = targetSize;
|
||||
if (confiner2D != null)
|
||||
{
|
||||
confiner2D.InvalidateBoundingShapeCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user