Hello all,
im just playing around trying to make a small game with my Girlfriend.
I wanted to Clamp my FOV between 100 and 20, so that my camera doesn’t zoom out so far.
I could use Cinemachine I know, I want to learn though and I don’t think that’s the best way.
I’ve gotten quite far IMO.
I just have a small problem I can’t figure out.
My two if’s are going against each other. I can’t say “if FOV > 20 && FOV <100” because that makes it not stop scrolling.
I know it’s not that difficult for most of yall but I’m struggling a bit so thanks for all the help!
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZoomHandler : MonoBehaviour
{
[SerializeField]
private float ScrollSpeed = 10f;
private Camera ZoomCamera;
float CamFOV = 0f;
// Start is called before the first frame update
private void Start()
{
ZoomCamera = Camera.main;
}
// Update is called once per frame
void Update()
{
CamFOV = Camera.main.fieldOfView;
if (CamFOV <= 100f) {
float FOV = Input.GetAxis("Mouse ScrollWheel") * ScrollSpeed;
ZoomCamera.fieldOfView -= FOV;
} else { }
if (CamFOV >= 20f) {
float FOV = Input.GetAxis("Mouse ScrollWheel") * ScrollSpeed;
ZoomCamera.fieldOfView -= FOV;
} else { }
//Debug.Log(CamFOV);
}
}