Add Camera controlled by player. #7 (#10)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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>
This commit is contained in:
41
Assets/Scripts/Input/PlayerCameraInputHandler.cs
Normal file
41
Assets/Scripts/Input/PlayerCameraInputHandler.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Input/PlayerCameraInputHandler.cs.meta
generated
Normal file
3
Assets/Scripts/Input/PlayerCameraInputHandler.cs.meta
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b94be55d5ec4fedb531d50297528d3b
|
||||
timeCreated: 1690824962
|
Reference in New Issue
Block a user