Created
October 7, 2019 10:22
-
-
Save verborghs/d3adb5057907fce06942b4e754947711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IImpulseCommand | |
{ | |
void Excute(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InputHandler | |
{ | |
public IImpulseCommand ACommand; | |
public IImpulseCommand BCommand; | |
public void Update() | |
{ | |
if(Input.GetButtonDown("A")) | |
ACommand.Excute(); | |
if(Input.GetButtonDown("B")) | |
BCommand.Excute(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InteractCommand : IImpulseCommand | |
{ | |
private PlayerBehaviour _player; | |
public InteractCommand(PlayerBehaviour player) | |
{ | |
_player = player; | |
} | |
public void Excute() | |
{ | |
_player.Interact(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JumpCommand : IImpulseCommand | |
{ | |
private PlayerBehaviour _player; | |
public JumpCommand(PlayerBehaviour player) | |
{ | |
_player = player; | |
} | |
public void Excute() | |
{ | |
_player.Jump(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Startup : MonoBehaviour | |
{ | |
[SerializeField] | |
private PlayerBehaviour _player; | |
[SerializeField] | |
private InputHandler _inputHandler; | |
private void start() | |
{ | |
_inputHandler = new InputHandler(); | |
_inputHandler.ACommand = new JumpCommand(_player); | |
_inputHandler.BCommand = new InteractCommand(_player); | |
} | |
private void Update() | |
{ | |
_inputHandler.Update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment