if statement always uses else

Hi i have this simple script:

 if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("1");
        }
        else
        {
            Debug.Log("0");
        }

Its should write 1 when the space bar is pressed and 0 when not pressed. But it just writes “0” What am i doing wrong?

First, if you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

Go read the docs for Input.GetKeyDown()

  1. it has to be used in Update()
  2. it only returns true on the one single frame that the key goes down.

Are you looking for Input.GetKey() perhaps?

Thanks for the advice i know relise how stupid it was to use GetkeyDown thanks a ton!