Cindy Page
4
Q:

unity key pressed

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
if(Input.GetKey(KeyCode.space))
	{
  		print("Space key was pressed")
	}
0
using UnityEngine;

public class Egsample_script : MonoBehaviour
{
    [SerializeField] KeyCode your_key;
    //select a key under inspektor
    void Update()
    {
        if (Input.GetKey(your_key))
        {
            print("your selekted key was pressed");
        }
    }
}
-1

New to Communities?

Join the community