Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • 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

avatar image
0
Question by Entyro · Aug 09, 2013 at 10:02 PM · guilightingkeypress

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;
                     
 
         }
     }
 
 }
 }

alt text alt text

2.jpg (341.9 kB)
1.jpg (321.4 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perchik · Aug 09, 2013 at 10:48 PM 0
Share

Perhaps you should show us the GUI where you actually "popup" the text to turn it on

avatar image RyanZimmerman87 · Aug 09, 2013 at 11:05 PM 0
Share

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.

avatar image Entyro · Aug 10, 2013 at 08:13 AM 0
Share

I've added some pics so you can understand more easily

avatar image Entyro · Aug 10, 2013 at 08:59 AM 0
Share

I fixed it, thanks for trying to help!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I center the gui created by this script? 0 Answers

How To Make GUI Buttons Load/Quit 1 Answer

Normal Crosshair (crosshair IS the mouse) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges