0

I tried to follow a Brackeys Unity Tutorial, but I can't seem to get it to work. With this script I should have an option to change the Value of Mouse Sensitivity and to add an object to the Player Body to transform it. But I see neither of those.

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()
    {
        
    }

    // 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;

    playerBody.Rotate(Vector3.up + mouseX);
    }
}
1
  • 1
    You need to drag the script onto the gameobject. Also make sure the file name is the same as the class i.e. MouseLook.cs
    – JeanLuc
    Commented Apr 16, 2022 at 19:22

2 Answers 2

1

Hard to answer without more context, however a few things come to mind.

Is your script on a GameObject in the scene?
Is the field playerBody assigned? The field is public and not assigned in the script itself.
The axis might not be set up for some reason, check the AxisManager in Unity to make sure they receive input, you can log their values with Debug.Log(Input.GetAxis("Mouse X"));.

If you provide more context it would be easier to tell what is going wrong, preferably the Log after starting the scene and a screenshot of the Inspector of the GameObject with the assigned script in the scene.

1

Have you attached the script to a game object in the scene?

Not much information is given but I would assume your script isn't being called as its not attached to any game objects in the scene.

Drag and drop the script to your desired game object, I believe in your case would be the player? or something attached or related to the player?

Not the answer you're looking for? Browse other questions tagged or ask your own question.