Annoying Scripting Impediment xD

I have a problem. I have a coding impediment. I am good-for-nothing, including coding. I am a failure, because of my impediment. It is not my fault. The therapist says its all in my head…
xD

I have a script that checks if a variable in another script is true and if the up arrow is pressed it will apply motion on the y-axis. That is all fine and dandy. The hard part is that I need to make it so that after the motion is applied, the script will wait for the user to release the key. When the user releases the key, the boolean in the other script is set to false, and has to be set to true again for the user to be able to activate it. It is pretty much a ‘one time use’ jet-pack.

I have tried many methods but none have worked… Any ideas?

well, to set it to false, use something like Input.GetKeyUp(KeyCode.UpArrow) and then inside the “if” statement change the bool to what ever you want

that does not work…

Here is how I would suggest going about this:

Script 1:

var applyMotion : boolean = true;

function Update () {
     if (applyMotion  Input.GetKeyDown("up")) {
          transform.Translate(0, 10 * Time.deltaTime, 0);
     }

     if (Input.GetKeyUp("up")) {
          applyMotion = false;
     }
}

Script 2:

var scr : yourScriptName; // Assign object containing script 1 to this

// Call this when you want to enable the jetpack again
function enableJetPack () {
     scr.applyMotion = true;
}

This will make it so that when the user releases the up key, the variable is set to false, so you have to set it to true again in order to use the jetpack.

Hope this helps.

ALMOST! Except that in my little test scene, the cube only moves up once per keypress, and does not go up while the key is held…

In MrPenguin’s script1, all you have to do is change

if (applyMotion  Input.GetKeyDown("up")) {

to

if (applyMotion  Input.GetKey("up")) {

The first returns true only in the first frame the key is pressed, while the second returns true as long as the key is held down.

Thank God!
You rock, man! Thanx!!! Thanks for all of the help!