how to create toggle button

i want to create a toogle button looking like this.

27027-photo.png

You need to create a GUISkin and here is the code I use:

    f_sfxSliderValue = Mathf.RoundToInt(f_sfxSliderValue);
	if(f_sfxSliderValue == 0)
	{
		mySkin.horizontalSlider.normal.background = buttonOption.backSlideRed;
	}
	else 
	{
		mySkin.horizontalSlider.normal.background = buttonOption.backSlideGreen; 
	}
	GUI.skin=mySkin;
	GUI.Box (new Rect(margin,offset, r_optionBackground.width / 2, sliderHeight),"SFX");

	if(f_prevSfxValue != f_sfxSliderValue)
	{
		audio.volume = f_sfxSliderValue;
		audio.Play ();
	}
	f_sfxSliderValue = GUI.HorizontalSlider(new Rect(halfWidth,offset, sliderHeight * 3f, sliderHeight), f_sfxSliderValue, 0, 1);
	f_prevSfxValue = f_sfxSliderValue;

You don’t need any GUI. You can work with sprites and colliders and an audio object (empty object with audio source and script for start playing and DontDestroyOnLoad). Make different sprites for on and off situation and put them in the Resources folder. Store a string in PlayerPrefs (“A” or “B”) to call the chosen sprite on scene loading. Don’t forget to set the PlayerPrefs string at first start.

Here is my code:
#pragma strict

var On : Sprite;
var Off : Sprite;

function Awake ()
{
PP ();
}

function Update () {

for (var touch : Touch in Input.touches) {

 	var hit:RaycastHit = new RaycastHit();
 	
	if (touch.phase == TouchPhase.Ended) {
		
		var ray = Camera.main.ScreenPointToRay (touch.position);
		if (Physics.Raycast (ray, hit, 100)) 
		if(hit.collider.gameObject == this.gameObject) 
        { 
			 gameObject.Find("AudioButton").SendMessage("playAudioButton");					
			if(GetComponent(SpriteRenderer).sprite == On)

			{
				GetComponent(SpriteRenderer).sprite = Off;
				PlayerPrefs.SetString("SetSpriteEffects", "A");
			}

			else

			{
				GetComponent(SpriteRenderer).sprite = On;
				PlayerPrefs.SetString("SetSpriteEffects", "B");
			}
			
		}
	}
}

}

function PP ()
{
yield WaitForSeconds (0.1);

			if(PlayerPrefs.GetString("SetSpriteEffects") == "B")
			{
			GetComponent(SpriteRenderer).sprite = On;	
			}
							
			else if(PlayerPrefs.GetString("SetSpriteEffects") == "A")
			{
			GetComponent(SpriteRenderer).sprite = Off;	
			}

}