if get key down unity
Code Example - 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");
}
}
}
unity key detection
if (Input.GetKeyDown(KeyCode.Space))
{
print("space key was pressed");
}
unity check if key pressed
if (Input.GetKeyDown(KeyCode.KEY))
Debug.Log(Input.GetKey)
void Update()
{
//get the input
var input = Input.inputString;
//ignore null input to avoid unnecessary computation
if (!string.IsNullOrEmpty(input))
{
switch(input)
{
case 'a': break;
case 'b': break;
}
}
}
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
}
}
onkeypressed unity
public void Update()
{
if (Input.GetKeyUp(KeyCode.X))
{
//do stuff
}
}