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 /
avatar image
0
Question by MFR Games · Jul 26, 2013 at 08:48 AM · lightcar

Brake Light Button

Hey fellas i got a question in unity about brake lights i am very new to unity i developed a car game but i can't seem to get the brake lights to work i created a script but when i place script it works but when i hold (s) it keeps turning the light on and off

and i want if i press (s) it keeps the light on but when i remove my finger it stops lighting.

Here's the script i made:

function Update() {

if (Input.GetButton("s")) {

 if (light.enabled == false)

     light.enabled = true;
     
     else
         
         light.enabled = false;
 }

}

can you send me the finished script thanks in advance

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gregzo · Jul 26, 2013 at 08:52 AM

Hi,

No I cannot give you the finished script.

Input.GetButtonDown and Input.GetButtonUp should work in your case : lights on when s down, off when up.

Comment
Add comment · Show 5 · Share
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 MFR Games · Jul 26, 2013 at 11:49 PM 0
Share

Now when i press (s) it lights but i have to press it again to turn off here's the script I've done with what you told me can you troubleshot the script:

function Update() {

if (Input.GetButtonDown("s")) {

 if (light.enabled == false)

     light.enabled = true;
     
     else  if (Input.GetButtonUp)
     {
     
             light.enabled = false;

     }
     
 }

}

avatar image AlucardJay · Jul 26, 2013 at 11:59 PM 0
Share

Look at the logic. Pseudocode :

 if button is down
 {
     turn light on
 }
 
 if button is up
 {
     turn light off
 }

Also, use the Unity Scripting Reference :

  • http://docs.unity3d.com/Documentation/ScriptReference/Input.html

  • http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html

  • http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonUp.html

Upvoted answer.

avatar image MFR Games · Jul 27, 2013 at 07:45 AM 0
Share

i honestly don't get it when i press "s" it turns the light on when i press it again turns off that's not what i want for the brake lights i want the lights to be on if i keep holding "s" but when i remove my finger it stops the light

avatar image gregzo · Jul 27, 2013 at 08:00 AM 0
Share
 if (Input.GetButtonDown("s")) 
 {
      light.enabled = true;
 }
 else if ( Input.GetButtonUp("s")) 
 {
      light.enabled = false;
 }

Please do a few scripting tutorials, UA won't write all your scripts for you.

avatar image MFR Games · Jul 27, 2013 at 10:08 AM 0
Share

now it stopped working even if i press "s"

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

How to make flary light reflection 1 Answer

Car wont drive again after red light 0 Answers

Find GameObject Position(x,z) and rotation(y) 1 Answer

How to turn on a light, then off with the same button. 1 Answer

Strange Lighting Glitch 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