- Home /
 
 
               Question by 
               ClassicGameJunkie · Oct 05, 2014 at 03:04 PM · 
                javascripttexturehideshow  
              
 
              Re-hiding a guiTexture
So with my incredibly limited knowledge of JS I've written a simple script to show an image on the screen, but I'm having trouble with hiding it when pressing the button again. The code works to show the image below:
 function Start () {
 guiTexture.enabled = false;
 }
 
 function Update(){
 if(Input.GetButton("Start")){
 guiTexture.enabled = true;
 }
 }
 
 
               I've tried several things but can't seem to get my head around it, my latest failed attempt is:
 #pragma strict
 
 function Start () {
 guiTexture.enabled = false;
 }
 
 function Update(){
 if(Input.GetButton("Start") && guiTexture.enabled = false;){
 guiTexture.enabled = true;
 }
 if(Input.GetButton("Start") && guiTexture.enabled = true;){
 guiTexture.enabled = false;
 }
 }
 
 
               I'm sure it's fairly simple for someone more verse in javascript, any ideas?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by robertbu · Oct 05, 2014 at 03:06 PM
Change GetButton() to GetButtonDown(). Then you can use the 'not' operator:
 #pragma strict
 
 function Start () {
     guiTexture.enabled = false;
 }
  
 function Update() {
     if(Input.GetButtonDown("Start")) {
         guiTexture.enabled = !guiTexture.enabled;
     }
 }
 
              Your answer