Playing Offline¶
In this section, you will add support for playing the game offline.
- Go to
Edit->ProjectSettings->Input manager. - Right-Click the input
VerticalandDuplicate Array Element. - Name the new input
Vertica1. - Remove the
Alt Negative ButtonandAlt Positive Buttonof the the oldVerticalinput. - Remove the
Alt Negative ButtonandAlt Positive Buttonof the the newVertical1input. - Set
Negative ButtontosandPositive Buttontowfor the oldVerticalinput. - Set
Negative ButtontodownandPositive Buttontoupfor the newVertical1input.

Next, select the PongFrameSyncEngineController component, set Engine Mode to Offline and Offline Player Count to 2.

Update the OnFrameSyncCollectPlayerInput method of PongFrameSyncEngineController.
protected override void OnFrameSyncCollectPlayerInput(FrameSyncEngine frameSyncEngine, FrameSyncGame game)
{
if (engineMode == EngineMode.Offline)
{
//player1 and player2 are created because we set Offline Player Count to 2.
FrameSyncPlayer player1 = game.GetPlayer(1);
FrameSyncPlayer player2 = game.GetPlayer(2);
//player1 uses w and s to move and uses g to trigger the ready event.
player1.SetInputY((FFloat)Input.GetAxis("Vertical"));
player1.SetInputReady(Input.GetKeyUp(KeyCode.G));
//player2 uses up arrow and down arrow to move and uses h to trigger the ready event.
player2.SetInputY((FFloat)Input.GetAxis("Vertical1"));
player2.SetInputReady(Input.GetKeyUp(KeyCode.H));
}
else
{
game.localPlayer.SetInputY((FFloat)Input.GetAxis("Vertical"));
game.localPlayer.SetInputReady(Input.GetKeyUp(KeyCode.G));
}
}
Now, you are ready to play the game in the offline mode. Just hit play. You should be able to move the paddles with the w, s keys or with the arrow keys.
To start the match, you can press g to make player1 ready, and press h to make player2 ready.
