wait for 3 seconds button??

im looking to script for a button.

when i press it it does somethink, but when i hold it for 3 seconds it does something else ??

Ok. Normally I’d tell you to learn your own scripting, but I love coding so much, I couldn’t pass up this uber easy question. For a 3d asset such as a cube you want to click, here’s the script.

private var i : int;

function OnMouseDown(){
   StartCount();
}

function OnMouseUp(){
   StopCount();
}

function StartCount(){
   for (i=0;i>-1;i++){
      yield WaitForSeconds(1);
                               }
}

function StopCount(){

   if (i>3){
      //Do your greater than 3 seconds of holding stuff here.
              }

   else{
      //Do your less than 3 seconds stuff here.
         }

   i = 0;

}

For determining how long a mouse button is held down, I think the following code may work:

private var mouseDownStart:float;
private var hasFired:boolean = false;
function Update () {
	if (Input.GetMouseButtonDown(0))
	{
		hasFired = false;
		mouseDownStart = Time.time;
	}
	if (Input.GetMouseButton(0))
	{
		if (!hasFired && (Time.time - mouseDownStart) >= 3)
		{
			// 3 seconds has passed with the mouse down
			hasFired=true;
			// Do something
		}
	}
}

The way this works is to note the time the mouse button was first held down and then, while it is still down, see if it has been 3 seconds since the mouse button was first held down. The guard prevents re-fires after 3 seconds.

its using GUI textures…i forgot to say This is the script for the touch button copied from the SideScroll tutorial n this is what i had so far:

function Start() {

    endTime = 0;

}

 

function Update() {

//:::::::::::::::::::::::::  H I T  ::::::::::::::::::::::::::::::      

    if (!hitTouchPad.IsFingerDown()) {

       canHit = true;

    }

 

    if (canHit && hitTouchPad.IsFingerDown()) {

       while( hitTouchPad.IsFingerDown() ){  

         if(endTime < 3){

          endTime += Time.deltaTime;

         }else{

                 ShowItems();

                 break;

            }

         }

         if( endTime < 3 ){

                hit = true;

           canHit = false;   

         } 

    }

 

    if ( hit ) {

       hit = false;

       //hit code

    }

}

 

function ShowItems(){

    //show other hit items

}