Anyone have a sensitivity slider script/tutorial used for an fps (using Unity's mouselook controller?)

Ive been trying to figure this out for months, it isnt hard, its just im a beginner and its a giant road block in my game. If anyone has their own FPS game using unity’s FPSController and mouselook script please help me it would be very very appreciated. :slight_smile: Also please tell me how to use it.

This post touches on how to do this, Unity made this quite confusing to modify since MouseLook is private: Unity 5 access First Person Controller Mouse Look Sensitivity via script - Questions & Answers - Unity Discussions

Basically, add this function to FirstPersonController.cs to allow us to modify the private variables:

 public void ChangeMouseSensitivity(float X, float Y){
     m_MouseLook.XSensitivity = X;
     m_MouseLook.YSensitivity = Y;
 }

Then on another script, write a function that takes the slider value and sets that using the previous function. This script should be on the player GameObject, where the FPS script is. Something like this:

using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;

public class ChangeSettings : MonoBehaviour {

    public Slider sensitivitySlider;

    public void ApplySensitivity()
    {
        GetComponent<FirstPersonController>().ChangeMouseSensitivity(sensitivitySlider.value, sensitivitySlider.value);
    }
}

Now in the editor, set sensitivitySlider to the one you want to use and add ApplySensitivity() as an OnClick event on the button used to apply the sensitivity. Hope this helped!

EDIT: You can make this even easier. Under the OnValueChanged event on the slider, add ApplySensitivity(). That way you can try the sensitivity in real-time.