Files
soccar2d/Assets/Scripts/CameraEffects.cs
T
2026-03-29 02:27:55 +05:30

49 lines
1.4 KiB
C#

using UnityEngine;
using DG.Tweening;
[RequireComponent(typeof(Camera))]
public class CameraEffects : MonoBehaviour
{
public static CameraEffects instance;
Camera cam;
[SerializeField]private float stretchFactor = 0;
[SerializeField]private bool isBeingStretched = false;
[SerializeField]private float minFov = 5;
[SerializeField]private float maxFov = 10;
[SerializeField]private float fovSpeed = 10;
[SerializeField] private float bounceDuration = 0.35f;
[SerializeField] private float bounceElasticity = 0.7f;
[SerializeField] private float bounceOvershoot = 0.2f;
void Awake()
{
instance = this;
cam = Camera.main;
}
void Update()
{
if(isBeingStretched){
float targetFov = minFov + stretchFactor * (maxFov - minFov);
cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, targetFov, Time.deltaTime * fovSpeed);
}
}
public void SetStretchFactor(float stretchFactor){
this.stretchFactor = stretchFactor;
isBeingStretched = true;
}
public void ReleaseStretchFactor(){
stretchFactor = 0;
isBeingStretched = false;
cam.DOOrthoSize(minFov, bounceDuration)
.SetEase(Ease.OutElastic, bounceElasticity, bounceOvershoot)
.OnComplete(() => {
stretchFactor = 0;
});
}
}