User Input
Tutorial
·
Beginner
·
+10XP
·
5 mins
·
(559)
Unity Technologies
In this tutorial, you will learn how to capture user keyboard input using the Update method and output to the console using Debug.Log.
Languages available:
1. User Input
Main.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Main : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//if space key pressed down
//print a message
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("space Key");
}
//if ey key held down
//print message
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Holding E");
}
//if f key is lifted up
//print f
if (Input.GetKeyUp(KeyCode.F))
{
Debug.Log("f");
}
}
}
Debug.Log
calls may not appear in the the Console by default. Be sure that they are turned on before testing.