0% found this document useful (0 votes)
8 views1 page

Mouse Look

This C# script controls mouse look for a player character in Unity. It gets mouse input, calculates rotation, and rotates the player body and camera transforms accordingly.

Uploaded by

tahu tek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Mouse Look

This C# script controls mouse look for a player character in Unity. It gets mouse input, calculates rotation, and rotates the player body and camera transforms accordingly.

Uploaded by

tahu tek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System.

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

public class MouseLook : MonoBehaviour


{
public float mouseSesitivity = 100f;
public Transform playerBody;

float xRotation = 0f;


// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}

// Update is called once per frame


void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSesitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSesitivity * Time.deltaTime;

xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);

transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);


playerBody.Rotate(Vector3.up * mouseX);
}
}

You might also like