Передвижение камеры в разные сторону с помощью зажатого колёсика мыши

Хочу реализовать передвижение камеры в игре с помощью зажатого колёсика мыши. Я хочу, чтобы когда я зажимал колёсико мыши и двигал камеру, она передвигалась в разные стороны (обычно такое есть в стратегиях). Я написал код, но он не работает. Что мне нужно дописать или добавить?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraMove : MonoBehaviour
{
    public float scrollSpeed = 25f;
    public float maxy = 30f;
    public float miny = 6f;
    public Vector3 dragStartPosition;
    public Vector3 dragCurrentPosition;
    public Vector3 newPosition;
    public float movementSpeed;
    public float movementTime;

        
    // Start is called before the first frame update
    void Start()
    {
        newPosition = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        HandelMovementInput();
        HandleMouseInput();
    }
    void HandelMovementInput()
    {
        Vector3 pos = transform.position;
        if (Input.GetKey(KeyCode.W))
        {
            newPosition += (transform.forward * movementSpeed);
        }
        if (Input.GetKey(KeyCode.S))
        {
            newPosition += (transform.forward * -movementSpeed);
        }
        if (Input.GetKey(KeyCode.D))
        {
            newPosition += (transform.forward * movementSpeed);
        }
        if (Input.GetKey(KeyCode.A))
        {
            newPosition += (transform.forward * -movementSpeed);
        }
        transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime);
        float scroll = Input.GetAxis("Mouse ScrollWheel");
        pos.y -= scroll * scrollSpeed * 100f * Time.deltaTime;
        pos.y = Mathf.Clamp(pos.y, miny, maxy);
        transform.position = pos;
    }
    void HandleMouseInput()
    {
        if (Input.GetMouseButtonDown(2))
        {
            Plane plane = new Plane(Vector3.up, Vector3.zero);

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            float entry;

            if (plane.Raycast(ray, out entry))
            {
                dragStartPosition = ray.GetPoint(entry);
            }

        }
        if (Input.GetMouseButton(2))
        {
            Plane plane = new Plane(Vector3.up, Vector3.zero);

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            float entry;

            if (plane.Raycast(ray, out entry))
            {
                dragCurrentPosition = ray.GetPoint(entry);

                newPosition = transform.position + dragStartPosition - dragCurrentPosition;
            }
        }
    }
}

Ответы (0 шт):