- Home /
 
              This question was 
             closed Aug 10, 2013 at 08:59 AM by 
             Entyro for the following reason: 
             
 
            The question is answered, right answer was accepted
Gui label text change
Hi!
I was wondering how you would make a script for a Gui label to change text on keypress. For example, my light switch script. On trigger, a text pops up "[E] Turn on lights", then it triggers some lights when pressing "E". The thing I want is to make a new text pop up when the light's already on, something like "[E] Turn off lights". Does anyone know what to add to my script if you want that to work?
 #pragma strict
 var buttonInRange;
 var buttonActivated;
 var doorIsOpen;
 var doorTimer : float;
 var lightSwitch : GameObject;
 var light1 : Light;
 var light2 : Light;
 var light3 : Light;
 var light4 : Light;
 var light5 : Light;
 var light6 : Light;
 var sound : AudioClip;
 public var guiSkin : GUISkin;
 
 
 doorIsOpen = false;
 doorTimer = 0.0;
 
 function OnTriggerEnter (c : Collider)
 {
     buttonInRange = true;
 }
 function OnTriggerExit (c : Collider)
 {
     buttonInRange = false;
 }
 function OnGUI()
 {
     if(buttonInRange == true)
     {
         GUI.skin = guiSkin;
         GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50),"[E] Turn on lights");
     }
 }
 function Update ()
 {
 
     if(doorTimer > 0)
         doorTimer -= Time.deltaTime;
     if(doorTimer < 0)
         doorTimer = 0;
     
     if(buttonInRange == true)
     {
         if (Input.GetKeyDown ("e"))
         {
             
             if(doorTimer == 0)
             {
                 if (doorIsOpen == false)
                 {    
                     AudioSource.PlayClipAtPoint(sound, transform.position);
                     lightSwitch.animation.Play("light switch");
                     doorIsOpen = true;
                     light1.enabled = true;
                     light2.enabled = true;
                     light3.enabled = true;
                     light4.enabled = true;
                     light5.enabled = true;
                     light6.enabled = true;
                     
                     
                 }
                     else {
                     AudioSource.PlayClipAtPoint(sound, transform.position);
                     lightSwitch.animation.Play("light switch off");
                     doorIsOpen = false;
                     light1.enabled = false;
                     light2.enabled = false;
                     light3.enabled = false;
                     light4.enabled = false;
                     light5.enabled = false;
                     light6.enabled = false;
                 }
                 
                 doorTimer = 0.3;
                     
 
         }
     }
 
 }
 }
 
               
 
               Comment
              
 
               
              Perhaps you should show us the GUI where you actually "popup" the text to turn it on
You could just add a bool to each light switch object and use that to deter$$anonymous$$e which text to display in your GUI?
Not sure if I'm following your problem specifically.