How to fix unstable boolean values? [possible bug]


I am creating an override boolean value for a game project I am working on. Only when the "t" key is pressed does this override activate (Input.GetKeyDown), and it is reversed upon lifting the "t" key (Input.GetKeyUp). The problem is that the value seems to be toggling elsewhere in the code. It is very bizarre!

This is where it is called:

if (Input.GetKeyDown("t")){
}else if (Input.GetKeyUp("t")){

**turretOverlord script functions**

    function editModeGo(isEditMode : boolean){

    function Update(){
        if (!editOverride){
            // playerMoveScript.editMode is ALWAYS true for this particular problem


private var editMode : boolean = false;

function Update () {
    print (editMode);

function setEdit(modeOn : boolean){

When I run this, the behavior changes each time I press/unpress "t": 1st time: "False", followed by an infinite stream of "True" 2nd time: a repeating stream of "False" then "True" then "True" 3rd time: a repeating stream of "False" then 4x "True" 4th time: a repeating stream of "False" then 6x "True" 5th time: a repeating stream of "False" then 8x "True"

What in the world could be causing this???!

If your "if input" stuff is actually outside a function, you'll want to move it inside a function (probably update).


Perhaps the problem is that GetKey expects a KeyCode argument. Try replacing "t" with KeyCode.T