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
1
Question by PotatoOrgyLt · Mar 04, 2012 at 02:34 PM · onturnsecondsoff

How to turn on a light by pressing and after few seconds turn it off

Hello, im making a muzzle flash and I want to add a light to it. So what I want to do is that the light would turn on when I press the button and after some time the light would be turned off. Im not sure what is wrong with the script... Thank you for answering.

var LightLength = 0.1;

function Update() {

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

   LightLengthOn();

 }

}

function LightLengthOn()

{

 LightLength.active = true;

 yield WaitForSeconds(LightLength);

 LightLength.active = false;

}

Comment
Add comment · Show 1
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 Essential · Mar 04, 2012 at 02:47 PM 0
Share

What's happening currently?

1 Reply

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

Answer by aldonaletto · Mar 04, 2012 at 02:51 PM

Dear God! Are you trying to turn the float variable LightLength active and inactive? You should use light.enabled instead (script attached to the light game object):

var LightLength = 0.1;

function Update() { if(Input.GetButtonDown("Jump")) { LightOn(); } }

function LightOn() { light.enabled = true; yield WaitForSeconds(LightLength); light.enabled = false; } But be aware that this will only illuminate the nearby objects. To show the muzzle flash you will need a muzzle object, and turn it on and off like the muzzle light. You can download the FPS Tutorial and "steal" the muzzle flash object from the machine gun model, then child it to your own weapon and use renderer.enabled to turn it on and off.

Comment
Add comment · Show 2 · 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 PotatoOrgyLt · Mar 04, 2012 at 03:25 PM 0
Share

Thank you for help! I added a light to my muzzle flash and it looks realy good

avatar image Essential · Mar 04, 2012 at 03:40 PM 0
Share

Potato, I would suggest ticking Aldonaletto's answer as correct so your question is marked as answered. ;)

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

6 People are following this question.

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

Related Questions

Turn on/off Script 3 Answers

Lights wont turn back on 1 Answer

Turn off multiple lights trigger 1 Answer

Everything in Unity starts and stops, starts and stops, on and on.. 0 Answers

how to turn off unity answer notification or email?? 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