How to change button.spriteState.pressedSprite sprite by script - Unity 4.7.1

The title says all, I already tryed everything.

I begin with the error it gives me :

error CS1612: Cannot modify a value type return value of UnityEngine.UI.Selectable.spriteState. Consider storing the value in a temporary variable

and the code that gives that error :

        cont.GetComponent<Button> ().spriteState.pressedSprite = theme.pressbuttons [0];
		pause.GetComponent<Button> ().spriteState.pressedSprite = theme.pressbuttons [1];
		help.GetComponent<Button> ().spriteState.pressedSprite = theme.pressbuttons [2];
       .... etc

First i tryed instantiating a Sprite object and assigning it theme.pressbuttons sprite, but it gives the same error.

Then I tryed instantiating a SpriteState object and assigning it the spritestate of the button to change tha sprite, this way it won’t give me the error but i don’t the get the sprite to be changed

The error tells me to store the value in a temp variable, I tryied for both the variables but it doesn’t work either way…
What I could try is storing the Button in a temp variable, but it doesn’t make sense to me, since I already tried with the attached SpriteState.

I think i’m missing something, the code to change the normal state sprite works because i only have to change the Image().sprite value, but this one accessing the Button().spriteState is not.

The Editor suggest me when I type “pressedSprite” a {get; set;} method but I don’t really know how to use it… Thanks for answers!

Oh, I’m using C# .

Sorry to revive such an old thread but this is the second result on Google when I searched for a similar issue I was having.

Played around with it a bit and this is what I found works:

SpriteState myStates;

myStates.pressedSprite = mySprite;

thisButton.spriteState = myStates;

The compiler doesn’t like the direct assignment of values to the properties of the button’s sprite state so you have to do it indirectly by creating a SpriteState element and assigning that to the button’s sprite state itself.

I hope that makes sense.