if and alse on GUI button and iTween

Hi everybody

here is a small menu test that I’am working on :
http://anthony.rollier.free.fr/anthony-rollier-blogs/bouton-test-02/WebPlayer.html

Even if it seems really easy, as a beginer I’am encountering many problem, so I came here to try to fix them.

How can I make the scares going back to there orinal position when I’am clicking a second time on the button “couleurs” using a if and else (or something else).

here is the code :

var couleur : GUISkin;

var carrerouge : GameObject;
var carrejaune : GameObject;
var carrevert : GameObject;
var carrenoir : GameObject;
var sW = Screen.width;

function Start (){

}

function OnGUI(){

//couleurs
GUI.skin = couleur;
if (GUI.Button(Rect(sW-200,325,200,50), “”)){
print(“bouton couleur pressed”);
iTween.MoveTo(carrerouge,{“y”:-.06, “delay”:.1});
iTween.MoveTo(carrejaune,{“y”:-.06, “delay”:.2});
iTween.MoveTo(carrenoir,{“y”:-.06,“delay”:.3});
iTween.MoveTo(carrevert,{“y”:-.06, “delay”:.4});
}
GUI.skin = null;

}

thanks for helping and excuse my English !

var pressed : boolean = false;

function Start (){
        }
                    
function OnGUI(){        
        //couleurs GUI.skin = couleur;
        if (GUI.Button(Rect(sW-200,325,200,50), "")){ print("bouton couleur pressed");
            if(pressed == false){
                iTween.MoveTo(carrerouge,{"y":-.06, "delay":.1});
                iTween.MoveTo(carrejaune,{"y":-.06, "delay":.2});
                iTween.MoveTo(carrenoir,{"y":-.06,"delay":.3}); 
                iTween.MoveTo(carrevert,{"y":-.06, "delay":.4}); } GUI.skin = null;
                pressed = true;
            }
            if(pressed == true){
                iTween.MoveTo(carrerouge,{"y":+.06, "delay":.1});
                iTween.MoveTo(carrejaune,{"y":+.06, "delay":.2});
                iTween.MoveTo(carrenoir,{"y":+.06,"delay":.3}); 
                iTween.MoveTo(carrevert,{"y":+.06, "delay":.4}); } GUI.skin = null;
                pressed = false;
            }
        }
    }

You’re not giving it a condition for if you press it a second time, use this.

hey, thanks for reply,
the code doesn’t seems to work at all, trouble with the “+”, it left “{”…

so I have try to modify it to this :

enter code

var couleur : GUISkin;
var carrerouge : GameObject;
var carrejaune : GameObject;
var carrevert : GameObject;
var carrenoir : GameObject;
var sW = Screen.width;

var pressed : boolean = false;

function Start (){
}

function OnGUI(){
//couleurs GUI.skin = couleur;
if (GUI.Button(Rect(sW-200,325,200,50), “”))
if(pressed == false){
print(“descente”);
iTween.MoveTo(carrerouge,{“y”:-.06, “delay”:.1});
iTween.MoveTo(carrejaune,{“y”:-.06, “delay”:.2});
iTween.MoveTo(carrenoir,{“y”:-.06,“delay”:.3});
iTween.MoveTo(carrevert,{“y”:-.06, “delay”:.4});
pressed = true;
}
GUI.skin = null;

        if(pressed == true){

print(“montée”);
iTween.MoveTo(carrerouge,{“y”:.06, “delay”:.1});
iTween.MoveTo(carrejaune,{“y”:.06, “delay”:.2});
iTween.MoveTo(carrenoir,{“y”:.06,“delay”:.3});
iTween.MoveTo(carrevert,{“y”:.06, “delay”:.4});
pressed = false;
}
GUI.skin = null;

}
here

but it still doesn’t work as I want…