Attach GUI element to newly spawned player as their GUI

Goal: Design and implement a multiplayer GUI. Specifically a hitpoints readout while also keeping the readout separate from other players in the same server.

I came across a few tutorials of the new 4.6 UI features and the typical method of adjusting the value of a slider or text is to:

  1. Attach a script to an object

  2. Write the GUI controls into the script (update hitpoints → change slider value, for example)

  3. Drag the GUI element from the hierarchy to the script in the inspector

The problem is the players with the health scripts attached are not spawned until they join a game. This means I would have to attach the slider to the script after the player spawns else I get object reference issues.

Suggestions? I am open to a better method as well. Thank you!

Prepare a Prefab with all the connections and references inside. Leave an empty public property for the player object to connect in.

When a player spawns, simply instantiate the prefab using Instantiate(), fill in the missing property and you’re good to go :slight_smile: