So when i try to rotate using my scroll wheel i usally dont get any input at all, it works some times but most of the time it returns 0 as the input. I am using unitys new input system.
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.InputSystem;
public class CameraController : MonoBehaviour
{
public InputActionAsset cameraControls;
private InputActionMap cameraMap;
private InputAction panAction;
private InputAction rotateAction;
private InputAction mouseRotateAction;
public float panSpeed = 10f;
public float rotationSpeed = 10f;
private Vector3 forwardDirection;
float rotateAmount;
private void Start()
{
forwardDirection = transform.forward;
}
private void Update()
{
Pan();
Rotate();
}
private void Pan()
{
Vector2 panInput = panAction.ReadValue<Vector2>();
float panX = panInput.x;
float panY = panInput.y;
Vector3 panMovement = forwardDirection * panY + transform.right * panX;
transform.position += panMovement * panSpeed * Time.deltaTime;
}
private void Rotate()
{
float rotateInput = rotateAction.ReadValue<float>();
transform.Rotate(Vector3.up * rotateInput * rotationSpeed * Time.deltaTime);
forwardDirection = transform.forward;
}
private void MouseRotation(InputAction.CallbackContext context)
{
Vector2 mouseDelta = Mouse.current.delta.ReadValue();
rotateAmount = mouseDelta.x * rotationSpeed * Time.deltaTime;
transform.Rotate(Vector3.up, rotateAmount);
}
private void MouseRotationOff(InputAction.CallbackContext context)
{
Debug.Log(rotateAmount);
}
private void OnEnable()
{
cameraMap = cameraControls.FindActionMap("CameraMap");
panAction = cameraMap.FindAction("PanAction");
rotateAction = cameraMap.FindAction("RotateAction");
mouseRotateAction = cameraMap.FindAction("MouseRotateAction");
mouseRotateAction.started += MouseRotation;
mouseRotateAction.canceled += MouseRotationOff;
cameraMap.Enable();
}
private void OnDestroy()
{
cameraMap.Disable();
}
}