press key run code unity c#

C#
if (Input.GetKeyDown(KeyCode.Space))
        {
            print("space key was pressed");
        }if(Input.GetKey(KeyCode.space))
	{
  		print("Space key was pressed")
	}
Source

Also in C#: