0

I'm learning C# and am wondering if anyone can tell me how to write this psedocode into the C# language

num = 0
when "space" pressed THEN
num = num + 20

cheers

FIN DEPIERRE
  • 21
  • 1
  • 5
  • Does this answer your question? [Form KeyUp and KeyDown events to change variables](https://stackoverflow.com/questions/8297648/form-keyup-and-keydown-events-to-change-variables) – Luuk May 01 '22 at 08:58

2 Answers2

2

This would depend on where you're implementing it. I checked your profile, and I assume you're using Unity. in the future, you should tag the question with Unity, if I assumed right.

// inside of the Update function
    if(Input.GetKeyDown("space"))
    {
        // do something, on key pressed.
    }
    if(Input.GetKey("space"))
    {
        // do something on key held OR pressed.
    }

You can change what key by changing "space" to a different key

1
Console.Write("\nPress 'Space' to exit the process...\n");
int num=0;
if (Console.ReadKey().Key == ConsoleKey.Spacebar)
{
   num += 20;
   Console.Write(num);
}
Bayram Eren
  • 422
  • 4
  • 6