Home > Mobile >  Unity - Getting Player Input
Unity - Getting Player Input

Time:04-04

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.

CodePudding user response:

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?

  • Related