idle-survivors/Assets/Scripts/Input/PlayerCameraInputHandler.cs
Michael 3043c54bc4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add Camera controlled by player. #7 (#10)
Adds the player camera as described in #7.

As a note for the future that I forgot to add as a comment here, the camera zoom and rotation should be tweened to give a smoother effect.

Reviewed-on: #10
Reviewed-by: zephyr <zephyr@noreply.localhost>
Co-authored-by: Michael <mep053@gmail.com>
Co-committed-by: Michael <mep053@gmail.com>
2023-07-31 19:10:41 -05:00

41 lines
1.3 KiB
C#

using DefaultNamespace;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Input
{
public class PlayerCameraInputHandler : MonoBehaviour
{
[SerializeField] private PlayerCameraController cameraController;
[SerializeField] [Range(0, 100)] private float rotationSensitivity;
[SerializeField] [Range(0, 1)] private float zoomSensitivity;
private bool _allowRotation;
public void OnInputZoom(InputAction.CallbackContext context)
{
var input = context.ReadValue<float>();
var zoomAmount = input * zoomSensitivity * Time.deltaTime;
cameraController.Zoom(zoomAmount);
}
public void OnInputRotate(InputAction.CallbackContext context)
{
if (context.phase != InputActionPhase.Performed) return;
if (!_allowRotation) return;
var input = context.ReadValue<float>();
var rotationAmount = input * rotationSensitivity * Time.deltaTime;
cameraController.RotateAround(rotationAmount);
}
public void OnInputHoldToRotate(InputAction.CallbackContext context)
{
_allowRotation = context.phase switch
{
InputActionPhase.Performed => true,
_ => false
};
}
}
}