You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
|
|
public float smoothSpeed = 8f;
|
|
public Vector3 offset;
|
|
|
|
public float scrollSensitivity = 2f;
|
|
public float minDistance = 2f;
|
|
public float maxDistance = 10f;
|
|
|
|
[SerializeField] private float distance;
|
|
|
|
void Update()
|
|
{
|
|
if (target == null) return;
|
|
|
|
float scrollInput = 0;
|
|
|
|
|
|
if (!InteractionManager.Instance.IsActive && !EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
|
}
|
|
|
|
distance -= scrollInput * scrollSensitivity;
|
|
distance = Mathf.Clamp(distance, minDistance, maxDistance);
|
|
|
|
Vector3 desiredPosition = target.position - transform.forward * distance + offset;
|
|
|
|
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
|
|
transform.position = smoothedPosition;
|
|
}
|
|
}
|
|
|