Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Object reference error

Discussion in 'Scripting' started by Jaylink631, Oct 2, 2023.

  1. Jaylink631

    Jaylink631

    Joined:
    Sep 17, 2023
    Posts:
    4
    I am getting an error
    ArgumentException: Input Axis Mouse X is not setup.
    To change the input settings use: Edit -> Settings -> Input
    UnityEngine.Input.GetAxis (System.String axisName) (at <dbc9087e67094ae597a416f542bc9023>:0)
    mouselook.Update () (at Assets/Player/mouselook.cs:22)


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

    public class mouselook : MonoBehaviour
    {

    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    void Start()
    {
    Cursor.lockState = CursorLockMode.Locked;
    }


    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);
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    The solution is right in your error message:
    To change the input settings use: Edit -> Settings -> Input


    Go into the input manager and fix your axes: https://docs.unity3d.com/Manual/class-InputManager.html

    If you don't have "Mouse X" it sounds like you must have deleted the default axes. You can always reset them from that menu by pressing the gear or "..." and clicking "reset"
     
  3. Jaylink631

    Jaylink631

    Joined:
    Sep 17, 2023
    Posts:
    4
    Thanks