I found a strange problem while programming keyboard input in Unity (v5.3.5).
public class AvatarInputMapperUnityContext : MonoBehaviour {
private AvatarController _avatarController;
public KeyCode JumpKey = KeyCode.Space;
public KeyCode LeftKey = KeyCode.A;
public KeyCode RightKey = KeyCode.D;
public KeyCode UpKey = KeyCode.W;
public KeyCode DownKey = KeyCode.S;
private Dictionary<KeyCode, WeaponTags> ShotKeys;
void Awake () {
_avatarController = GetComponent<AvatarController>();
ShotKeys.Add(KeyCode.I, WeaponTags.Pistol);
ShotKeys.Add(KeyCode.O, WeaponTags.Shotgun);
}
void Update () {
if (Input.GetKeyDown(JumpKey)){
_avatarController.JumpSignal();
}
}
}
Now, when the ShotKeys.Add...
lines are commented out everything works fine. But when I uncomment them, the program never reaches the _avatarController.JumpSignal()
line, and none of the other directional keys (w,a,s,d) work. What can be the reason?