unity check if key pressed
Code Example - unity check if key pressed
if (Input.GetKeyDown(KeyCode.KEY))
unity key detection
if (Input.GetKeyDown(KeyCode.Space))
{
print("space key was pressed");
}
if get key down unity
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown("space"))
{
print("space key was pressed");
}
}
}
press key run code unity csharp
if(Input.GetKey(KeyCode.space))
{
print("Space key was pressed")
}
unity key pressed
//Triggers if Space is pressed
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//Your code
}
}
csharp unity detect any keyboard input
// Detect any keyboard input but not mouse input
private void Update()
{
if (Input.anyKeyDown && !(Input.GetMouseButtonDown(0)
|| !Input.GetMouseButtonDown(1) || !Input.GetMouseButtonDown(2)))
{
Debug.Log("No mouse pressed!");
}
}
how to get keyboard input in unity
//https://docs.unity3d.com/ScriptReference/KeyCode.html - ALL KEYCODES