I’ve been trying to make a third-person camera with zooming functionality that I can control manually via right-clicking and dragging; however, when I attempt to add said functionality, the camera is disabled due to me being unsure where I have to put my if statement of inputting the right mouse button. I’m using the Unity 2021 editor if that information helps people figure out my situation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private const float LOW_LIMIT = 0.0f;
private const float HIGH_LIMIT = 85.0f;
[SerializeField]
private float _mouseSensitivity = 3.0f;
private float _rotationY;
private float _rotationX;
[SerializeField]
private Transform _target;
[SerializeField]
private float _distanceFromTarget = 3.0f;
private float ScrollSpeed = 40;
private Vector3 _currentRotation;
private Vector3 _smoothvelocity = Vector3.zero;
[SerializeField]
private float _smoothTime = 0.2f;
[SerializeField]
private Vector2 _rotationXMinMax = new Vector2(-40, 40);
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * _mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * _mouseSensitivity;
_rotationY += mouseX;
_rotationX += mouseY;
_rotationX = Mathf.Clamp(_rotationX, _rotationXMinMax.x, _rotationXMinMax.y);
Vector3 nextRotation = new Vector3(_rotationX, _rotationY);
_currentRotation = Vector3.SmoothDamp(_currentRotation, nextRotation, ref _smoothvelocity, _smoothTime);
transform.localEulerAngles = _currentRotation;
transform.position = _target.position - transform.forward * _distanceFromTarget;
_distanceFromTarget -= Input.GetAxis("Mouse ScrollWheel") * ScrollSpeed;
}
}