StatsScared
15
Q:

if get key down unity

// KeyCode.Space : The key you press
// GetKeyDown : Is true once, when the key is pressed 
// If you want it to be true WHILE the key is pressed, try GetKey() instead
if(Input.GetKeyDown(KeyCode.Space))
{
	// Do something
}
4
if (Input.GetKeyDown(KeyCode.Space))
        {
            print("space key was pressed");
        }
15
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            print("space key was pressed");
        }
    }
}
5
Input.GetKey(KeyCode.Space))
2
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;
        }
    }
}
0

New to Communities?

Join the community