PlayerLook | Unit 9

PHOTO EMBED

Tue May 17 2022 21:19:40 GMT+0000 (UTC)

Saved by @BiscuitTinx #c#

using System;
using UnityEngine;

public class PlayerLook : MonoBehaviour
{
    [Header("Sensitivity")]
    public float sensX = 50f;
    public float sensY = 50f;

    [Header("Camera & Orientation Transforms")]
    [SerializeField] private Transform cam;
    [SerializeField] private Transform orientation;

    private float mouseX;
    private float mouseY;

    private float multiplier = 0.01f;
    
    float xRotation = 0f;
    float yRotation = 0f;

    private void Update()
    {
        cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientation.transform.rotation = Quaternion.Euler(0, yRotation, 0);
    }

    public void ReceiveInput(Vector2 mouseInput)
    {
        mouseX = mouseInput.x;
        mouseY = mouseInput.y;

        yRotation += mouseX * sensX * multiplier;
        xRotation -= mouseY * sensY * multiplier;

        xRotation = Mathf.Clamp(xRotation, -85f, 85f);
    }
}
content_copyCOPY