As outlined in Unity in Practice 0005 – Create C# Script – Wonderful Code See , we created a Ball.cs C# script which allows us to capture keyboard input within the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Space key was pressed.");
}
if (Input.GetKey(KeyCode.Space))
{
Debug.Log("Space key is being held down.");
}
if (Input.GetKeyUp(KeyCode.Space))
{
Debug.Log("Space key was released.");
}
}
}
