Hey there. At the moment I’m working on this Camera Control script with the sole purpose being that you can orbit the character by holding down right click, although when I stop clicking I want the camera to return to the normal third person perspective and copy the rotation of the player. I tried using various if statements and I created a “click” boolean as a method of returning if “click” was false, but nothing worked. Any Ideas?
Thanks guys
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour
{
private const float Y_ANGLE_MIN = 0.0f;
private const float Y_ANGLE_MAX =70.0f;
private bool click=false;
public Transform lookAt;
public Transform camTransform;
public float distance = 10.0f;
private float currentX = 0.0f;
private float currentY = 45.0f;
private float sensitivityX = 10f;
private float sensitivityY = 5f;
private void Start()
{
}
private void Update()
{
if (Input.GetMouseButton(1))
{
currentX += (Input.GetAxis(“Mouse X”) * sensitivityX);
currentY += (Input.GetAxis(“Mouse Y”) * sensitivityY);
click = true;
}
else
{
click = false;
}
currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
}
private void LateUpdate()
{
Vector3 dir = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt(lookAt.position);
}
}