Today when I went to use the script that controls movement I could not get Input.GetKey nor Input.GetKeyDown to work at all. Even simplifying the script to this, when the scene runs (with a gameobject with the script attached in it of course) the only one of the two debug logs below that runs is the else statement one. No matter how much I mash the d key nothing happens. I also tried various other key codes including other letters, numbers, shifts, all to no avail. When I searched for the problem I saw that this could happen if the code was in in Update, but even below you can see that it is. Anybody have an idea why Unity can’t catch any keys?
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
void Update()
{
if (Input.GetKey(KeyCode.D))
{
Debug.Log("Detected the key");
}
else
{
Debug.Log("Went into else");
}
}
}
Is the script attached to any game object? I know you say it is. Maybe add a
– Graham-DunnettStartfunction that has aDebug.Log()so you know the script is executed.The script is definitely running and attached to an object as I do get the "Went into else" message every frame.
– BijakHave you tried it with a different Key than D?
– ChernoYeah, I tried a few other letters, a number, and left shift all with no luck.
– BijakIf you remove the Debug in the else scope? Because maybe you just miss the message...
– InvincibleCat