- Home /
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
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
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;
}
}
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.
Yep i know that but can u please send me the complete code (with my piece of code, please please ? )
im newbie in scripting
If I give you a fish, will you come back for more? If I $$anonymous$$ch you to fish, will you $$anonymous$$ch others?
:( dude but i dont know anything of scripting , u drop the fish to the water xD
Your answer
Follow this Question
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