- Home /
Question by
lehailam3c · Dec 31, 2021 at 10:59 AM ·
scripting problemscript error
The script don't inherit a native class that can manage a script.
Hi!
soo this is my code
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.EventSystems;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation;
void Start()
{
//Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = 0;
float mouseY = 0;
/*
if(Mouse.current != null)
{
mouseX = Mouse.current.delta.ReadValue().x;
mouseY = Mouse.current.delta.ReadValue().y;
}
if (Gamepad.current != null)
{
mouseX = Gamepad.current.rightStick.ReadValue().x;
mouseY = Gamepad.current.rightStick.ReadValue().y;
}
//float mouseX = Input.GetAxis("Mouse X");
//float mouseY = Input.GetAxis("Mouse Y");
*/
if (Touchscreen.current.touches.Count == 0)
return;
if (EventSystem.current.IsPointerOverGameObject(Touchscreen.current.touches[0].touchId.ReadValue()))
{
if (Touchscreen.current.touches.Count > 1 && Touchscreen.current.touches[1].isInProgress)
{
if (EventSystem.current.IsPointerOverGameObject(Touchscreen.current.touches[1].touchId.ReadValue()))
return;
Vector2 touchDeltaPosition = Touchscreen.current.touches[1].delta.ReadValue();
mouseX = touchDeltaPosition.x;
mouseY = touchDeltaPosition.y;
}
}
else
{
if (Touchscreen.current.touches.Count > 0 && Touchscreen.current.touches[0].isInProgress)
{
if (EventSystem.current.IsPointerOverGameObject(Touchscreen.current.touches[0].touchId.ReadValue()))
return;
Vector2 touchDeltaPosition = Touchscreen.current.touches[0].delta.ReadValue();
mouseX = touchDeltaPosition.x;
mouseY = touchDeltaPosition.y;
}
}
mouseX *= mouseSensitivity;
mouseY *= mouseSensitivity;
xRotation -= mouseY * Time.deltaTime;
xRotation = Mathf.Clamp(xRotation, -80, 80);
transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
playerBody.Rotate(Vector3.up * mouseX * Time.deltaTime);
}
}
and this is the image
untitled.png
(418.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051116im_/https://answers.unity.com/themes/thub/images/avi.jpg)