'Unity - Getting Player Input
I am making a basic game in Unity and needed to know how to get the input of a player. When I searched this up, I got the same result on every website saying me to put in a line of code.
I tried putting in this line of code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrScrScrScrScr : MonoBehaviour
{
public GameObject Square;
private MeshRenderer myRenderer;
// 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.");
}
}
}
This did nothing and each time I pressed space nothing happened.
Solution 1:[1]
Nothing wrong with that code. Did you put this script on a GameObject in your scene? Are you looking at the console to see if it's spitting out the Debug? Finally... what is up with the class name?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vastlee |
