Ready Up And Die!

Written by JesusLuvsYooh / StephenAllenGames.co.uk

End Result:

1: To create a “ready up” feature, this will prevent players from moving until server/host says go.

2: An “isDead” player status to create a death and respawn.

Part 1:

Blank Project, import Mirror from Asset Store/ Discord Releases unity package.

Open up your scene, for this guide we will use Mirror/Examples/Tanks

You should be familiar with the examples, if not, have a quick play, build and run, join yourself by having two games on same PC connecting via 'localhost'.

Mirror/Examples/Tank/Scenes/Scene

Part 2:

Create a script called SceneScript, due to this guide modifying Mirrors Example scenes, make sure it is in same folder as Tank script.

Add this script onto a game object in the scene, also named SceneScript, this will be our canvas to player link as well as our 'scene manager', then attach a NetworkIdentity component, like below.

Part 3:

Open up this SceneScript.cs, and add the following code, parts will be commented to explain :)

Part 4:

Now open Tank.cs, this is the guides equivalent to your eventual PlayerScript.

And in the Update function, below the isLocalPlayerCheck, add: if (sceneScript.readyStatus != 1) return;

This will stop the tanks below code (movement and projectile firing) from running until ready.

Add the code at the bottom of Tank.cs, after the “RpcOnFire” ends.

(But still inside the namespace { } )

Part 5:

For this method during death and respawn, rather than destroying the player, we will hide and reshow it.

Open up the Tank player prefab, and add the two child objects to the “Objects To Hide” array, “ProjectileMount” is just an empty position marker, and does not need to be added.

Upon the sync var change of “isDead”, the hook callback will cycle through this array.

Part 6:

Create a Canvas in the scene, by either right clicking, UI canvas, or the menu at top, GameObject, UI, Canvas. Set the canvas scaler to “Scale with Screen Size”, this will help with keeping everything same size, on both low and high resolution screens, and is best to set before adding Canvas contents.

Create your Unity Canvas UI, with a text, and 3 buttons, label them for easier reference.

Here I have placed Status text at top, Server Set Ready button in the middle, and the Die and Respawn buttons to the right. After this set the variables to the correct UI on your SceneScript, like below.

Part 7:

Build and Run!

Enjoy :)

(To help with side by side play testing - Project settings, Player, Resolution and Presentation, Fullscreen Mode to “Windowed”.)

Last updated