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 pwnisher · Sep 21, 2012 at 10:12 PM · 3dflashlight

How to make Flashlight timer.

Hi i have this script for my flashlight turn on and off, and play audio,

var linkedLight : Light; var shootSound:AudioClip;

function Update () { if(Input.GetKeyDown("f")){ linkedLight.enabled = !linkedLight.enabled; audio.PlayOneShot(shootSound); } }

but i need to add a script when I have caught a long time is running out

thanks a lot

Comment
Add comment · Show 2
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 AlucardJay · Sep 22, 2012 at 12:23 AM 0
Share

Here are some links to help the average new Unity user :

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/

the Unity Wiki : http://wiki.unity3d.com/index.php/Tutorials

A list of resources : http://answers.unity3d.com/questions/12321/how-can-i-start-learning-unity-fast-list-of-tutori.html

avatar image AlucardJay · Sep 22, 2012 at 12:28 AM 0
Share

This is something I wrote for another answer, in response to : Ive looked at a few different ways of making a timer but there not making any sense to me, could you help me out?

I personally have seen 2 types of timer/counter. The first method is with a 'counter' and a maximum value.

 var counter : float = 0.0;
 var counter$$anonymous$$ax : float = 5.0;
 
 function Update()
 {
     if ( counter > counter$$anonymous$$ax )
     {
        // do stuff
        // reset counter
        counter = 0.0;
     }
     // increment counter over time, therefore its a Timer
     counter += Time.deltaTime;
     
     // increment counter with an inter value (like counting frames)
     // counter ++; // like this, counter can be an integer
 }


the second method is using Time.time itself, but it still need an offset value to work.

 var timer : float = 0.0;
 var timerDelay : float = 5.0;
 
 function Update()
 {
     if ( Time.time > timer )
     {
        // do stuff
        // reset timer
        timer = Time.time + timerDelay;
     }
 }

1 Reply

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

Answer by DaveA · Sep 21, 2012 at 10:14 PM

Make a float var like 'capacity' and set it to some number. In Update, if the light is enabled, subtract a small amount from capacity. When it gets to zero, turn the light off. For extra fun, you might want to wait until the capacity is about 10%, then start setting the light's intensity to smaller values until it reaches zero.

Comment
Add comment · Show 3 · 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 pwnisher · Sep 21, 2012 at 10:39 PM 0
Share

Yep i know that but can u please send me the complete code (with my piece of code, please please ? )

im newbie in scripting

avatar image DaveA · Sep 21, 2012 at 10:55 PM 1
Share

If I give you a fish, will you come back for more? If I $$anonymous$$ch you to fish, will you $$anonymous$$ch others?

avatar image pwnisher · Sep 21, 2012 at 11:03 PM 0
Share

:( dude but i dont know anything of scripting , u drop the fish to the water xD

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

11 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

Related Questions

Animation flashlight when run 4 Answers

Adding force to a bullet 3 Answers

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

Destroy GameObject and play sound 1 Answer

Menu with 3D-objects - using swipe on iPhone 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