Change guiTexture at runtime

Hi,

I want to change the background image when I click a button. So I'm trying to do this like:

var texture1 : GUITexture;
var texture2 : GUITexture;

var someTexture : GUITexture;
someTexture = texture1;
guiTexture.texture = someTexture;

function Update () {
}

function OnGUI() {

    if(GUI.Button(Rect(0,0,100,40),"Cambia fondo")){
        if(someTexture == texture1) {
            someTexture = texture2;
        } else if (someTexture == texture2) {
            someTexture = texture1;
        }   

    }
}

But I'm getting this error: InvalidCastException: Cannot cast from source type to destination type. changeTexture.Main () (at Assets/changeTexture.js:7)

which is this line:

guiTexture.texture = someTexture;

Thank you very much in advance

The texture member of a `GUITexture` is a `Texture`, not a `GUITexture`. It sounds like you either want to make `texture1` and `texture2` have type `Texture` instead of `GUITexture`, or (if you actually want to copy the texture from a different `GUITexture`) do `guiTexture.texture` = `texture1.texture` or the like.

(I'm not sure what you intend `someTexture` to be. It doesn't seem to serve a purpose here.)