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
CodePudding user response:
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
CodePudding user response:
Console.Write("\nPress 'Space' to exit the process...\n");
int num=0;
if (Console.ReadKey().Key == ConsoleKey.Spacebar)
{
num = 20;
Console.Write(num);
}