Unity 4.6 Slider to change script Float?

What i am trying to get is the slider value to change the mouse sensitivity witch i can link into code? or the actual value to the sensitivity? essentially what i am trying to do is this but instead of the hSliderValueX i want it the value of the gui slider:

using UnityEngine;
using System.Collections;

public class Gui : MonoBehaviour {
	public float hSliderValueX = 3F;
	void OnGUI() {
		MouseLook playerScript = GetComponent<MouseLook>();
		hSliderValueX = GUI.HorizontalSlider(new Rect(25, 25, 100, 20), hSliderValueX, 1.0F, 5.0F);
		playerScript.sensitivity.x = hSliderValueX;
	}
}

Attach the script below to a game object.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;    // Remember to include this
 
public class Gui : MonoBehaviour {
    public Slider hSlider;
    MouseLook playerScript;

    void Start()
    {
        playerScript = GetComponent<MouseLook>();
    }
    void Update() {
        playerScript.sensitivity.x = hSlider.value;
    }
}

Assign your Slider to the hSlider variable from either the inspector or you can get the slider component using GetComponent on your Slider game object in Start() function of this script.

Or you can also set the value to only be updated when slider changes. For that instead of Update create a function for accessing it when the value of slider changes.

public void OnhSliderChanged() {
        playerScript.sensitivity.x = hSlider.value;
}

And call this function from the On Value Changed for the intended slider. Remember this function has to be public in order to be accessed from your slider’s On Value Changed event.