What are you supposed to write when you want to mesure how long you press a button

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.

How do you do this?

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

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.

You could try something like this,

using UnityEngine;
using System.Colletions;

public class HoldingDown : MonoBehavior
{
	protected float requiredTime = 1.0f, lastPressed = 0.0f; // rT = 1 second in time
	protected bool hasHeld = false; // Haven't done it yet
	
	public void Update()
	{
		if(Input.GetKey(KeyCode.E)) // This is being held, not just pressed down
		{
			if(lastPressed == 0.0f)
			{
				lastPressed = Time.time;
			}

			hasHeld = true;
			
			if(hasHeld) // Precautionary, I've had things glitch before.
			{
				if(Time.time - requiredTime > lastPressed)
				{
					// Your Logic
				}
			}
		}else{
			hasHeld = false;
			lastPressed = 0.0f;
		}
	}
}