changing a buttons texture when it pressed ?

I have designed a set of textures for a button (10 textures),when button is not pressed one of them is assigned to it, what i want is when I press the button ,it switches it’s texture from 1 to 10 and show every texture(Like playing an animation when button is pressed),I 've written the following code but it’s not working the way it should!

	public int lenth;
	public Texture[] text=new Texture[10] ;
	Texture sampleText;
	public GUISkin skin1;


	void Start () 
	{
		sampleText=text[0];
	
	}
	
	

	void OnGUI()
	{
		GUI.skin=skin1;
		if (GUI.Button(new Rect(10, 10, lenth, lenth), sampleText))
		{
			for (int i=1;i<10;i++)
			{
				sampleText=text*;*
  •  	}*
    
  •  }*
    
  • }*
    }

Thank Eric

http://wiki.unity3d.com/index.php?title=Texture_swap_animator

This little code snippet is very versatile. We’ve used it for all sorts. Small movie clips, animated electric skin, anything you can think of involving multiple textures. Easily modified to fit many situations.

Fornoreason1000 is right. Your for loop is going to play through its entire sequence before the game will refresh OnGUI().

Here’s some code with a coroutine to get you started:

    void OnGUI()
    {
        GUI.skin = skin1;
        if (GUI.Button(new Rect(10, 10, lenth, lenth), sampleText))
        {
            StartCoroutine(PlaySequence());
        }
    }

    IEnumerator PlaySequence()
    {
        for (int i = 0; i < text.Length; i++)
        {
            sampleText = text*;*

// To wait for a certain length of time in seconds
yield return new WaitForSeconds(0.1f);

// To wait for a certain number of frames
for (int j = 0; j < desiredNumberOfFrames; j++)
{
yield return null;
}
}
}