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?
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.