Now that we have the core ingredients of the Command pattern and our replay system in place, it is time to test whether it works:
- The first class we will implement is InputHandler. Its primary responsibility is to listen for the player's inputs and invoke the appropriate commands. However, because of its length, we will review it in two parts:
using UnityEngine;
namespace Chapter.Command
{
public class InputHandler : MonoBehaviour
{
private Invoker _invoker;
private bool _isReplaying;
private bool _isRecording;
private BikeController _bikeController;
private Command _buttonA, _buttonD, _buttonW;
void Start()
{
_invoker = gameObject.AddComponent<Invoker>();
_bikeController = FindObjectOfType<BikeController>();
_buttonA = new TurnLeft(_bikeController);
_buttonD = new TurnRight(_bikeController);
_buttonW = new ToggleTurbo(_bikeController...