I’m trying to build a small demo of my game and I need to detect user input.
The user should control the direction of the game by using the arrow keys.
I’m using it like this:
void Update()
{
if(Input.GetKeyDown(KeyCode.Space)) {
current = startGameState;
}
if(current == null || current.GameOver) return;
if(Input.GetKeyDown(KeyCode.UpArrow)) {
current = current.DoAction(new MoveAction(MoveAction.Directions.NegativeY));
}
if(Input.GetKeyDown(KeyCode.DownArrow)) {
current = current.DoAction(new MoveAction(MoveAction.Directions.PositiveY));
}
if(Input.GetKeyDown(KeyCode.LeftArrow)) {
current = current.DoAction(new MoveAction(MoveAction.Directions.NegativeX));
}
if(Input.GetKeyDown(KeyCode.RightArrow)) {
current = current.DoAction(new MoveAction(MoveAction.Directions.PositiveX));
}
foreach(var tile in current.Board.Tiles) {
var tileObject = GameObject.Find(tile.Id.ToString());
if(tileObject == null) continue;
tileObject.transform.position = new Vector3(tile.PosX,0.25f,-tile.PosY);
}
gameOverText.SetActive(current.GameOver);
refreshButton.SetActive(current.GameOver);
}
When I’m running it inside Unity it works as expected. But when I create a build and run it on my MacBook the controls do nothing.
Am I just missing something?