I know what it is for pressing a button but what is it for holding down a key?
I want to make a script where you are supposed to hold a key for an amount of time to active something. If you hold the mouse down longer, you’ll make it even more powerful (do not include this in the script)
Example:
if(Input.GetKey(KeyCode.Space)"one second") {
}
I am aware of that typing “one second” doesn’t work, I just simply wanted to explain this better.
Look at the Static Functions section available with Input, in above link.
Make a little timer:
private var timer : float = 0.0;
private var timerStorage : float = 0.0;
function Update()
{
if ( Key Is Held Down )
{
timer += Time.deltaTime;
if ( timer > someVar )
{
//Do Stuff
//timer = 0.0; // if you need
}
}
if( Key Is Let Go )
{
timerStorage = timer; //Do what you want with it
timer = 0.0;
}
}
See if they pressed the key this frame. (GetKeyDown)
If they did press the key this frame, record the current time.
If they didn’t press the key this frame, but the key is pressed (GetKey) then they must be holding the key down, so check the current time against the time you recorded.
If the current time minus the time recorded is a certain amount (like 1 second), then they have held it down enough.