Unity how to change mouse sensivity with slider?

Hey guys so I have a problem I managed to make a slider to adjust the audio, works fine but only for main menu. I can’t get it to work for the mouse sensitivity. Also how do I for example adjust the audio from 1 scene but need to adjust volume from another scene? Here is my code:

using UnityEngine;
using System.Collections;

public class OptionsScript : MonoBehaviour {
    //used to adjust value of slider
     float hSliderValue = 1.0f;

   float MSliderValue = 1.0f;

    void OnGUI()
    {
       
        //makes a new slider
        hSliderValue = GUI.HorizontalSlider(new Rect(650, 300, 100, 30), hSliderValue, 0.0f,1.0f);
       
        //this is used a label to show user it changes volume
        GUI.Label(new Rect(520,293,200,20), "Change game volume");
       
        //with this get the audio source component and change the variable value
        GetComponent<AudioSource>().volume = hSliderValue;

        //this below is for the mouse sensivity
        MSliderValue = GUI.HorizontalSlider(new Rect(653, 330, 100, 30), MSliderValue, 0.0f, 1.0f);

        //this is used a label to show user it changes mouse sensitivity
        GUI.Label(new Rect(500, 323, 200, 20), "Change mouse sensitivity");

    }
}

Hello,

I don’t think there a parameter allowing you to change mouse sensitivity at runtime. You can edit the InputManager in project settings but it seems you can’t change the value at runtime (doc, related thread)
You still can use your own sensitivity var and use it to change the mouse speed in camera script if that’s only for camera.

About using the menu in multiple scene, that depends how you load your scene. But you should be able to use DontDestroyOnLoad, in order to make your object persistent form a scene A to a scene B.

Some suggestions :

  • take a look at the new UI system for Unity.
  • i think that’s a good habit to “cache” components that are often used. OnGUI is a function that is constantly executed. Using a cached component save some process time :
AudioSource audioSource;

void Awake(){
   audioSource = GetComponent<AudioSource>();
}
void OnGUI(){
   //[...previous code]
     audioSource.volume = hSliderValue;
}

Ok thanks ill try.

bump