key release of up arrow

when i release the up arrow key the gui button should appear.when i press up arrow the gui button should dis appear.after the release of the up arrow only i want the gui button should appear.

    var a1 = 0;

    function Update()
                   {

   if (Input.GetKeyUp (KeyCode.UpArrow))
                     {
                     a1 =1;
                     }

                   }

     function OnGUI()
                 {
           if(a1 == 1)
                 {
      GUI.Button(Rect(100,300,100,50),"button");    
                 }

                 }

when i release the uparrow the gui button is not appearing immediately. it is appearing after a delay of time or after the three or four time the release of the up arrow. i want the gui button to appear as i first release of the up arrow.

Is this a question? If you're asking people to write your scripts for you, you may have trouble with that. Use GetKeyUp() for key up events.

it is not working for me that why

1 Answer

1

Doing it this way you will have to set a1 back to 0 when the key is down. Currently you start a1 as 0, set it to 1 and then leave it like that. So your GUI button will always be drawn after the first KeyUp event.