- Home /
Question by
KhalfanCreative · Feb 17, 2020 at 03:56 PM ·
mousehidelook
xRotation is not working,xRotation is not working why?
help me xRotation is not working its saying its not a code i think
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour {
public float mouseSensitivity = 100f;
public Transform playerBody;
// 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") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
} , help this is not working? why its saying xRotation is not working
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour {
public float mouseSensitivity = 100f;
public Transform playerBody;
// 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") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
Comment
Answer by Chiarc · Dec 17, 2021 at 12:35 PM
You have not defined xRotation.
Underneath "public Transform playerBody;" you can put in "float xRotation = 0f;".
Your answer
Follow this Question
Related Questions
Hiding a Cursor? 3 Answers
Mouse Look Help 4 Answers
Javascript version of 'Mouse look' script? 1 Answer
Cursor " Hide" is not Immediate, what's wrong? 0 Answers
how to find mouse look 1 Answer