The Player Object - LucaBGt/DigitalGretaDoc GitHub Wiki
This is the object spawned in by the NetworkManager. In older Versions, the NetworkManager spawned in only one object with different parts (character creation), but this has been swapped in favor of pre-made characters. This prefab object should be finalized and afterwards cloned with visual changes for the different characters.
The Player Child Objects:
- 3D: Contains the 3D Model of the player that is culled after a certain distance.
- 2D: Contains the 2D Model of the player that is culled after a certain distance.
- UI: Contains all Player Specific UI.
- Floating Info: The Data of the Player ("Username") floating above the player. Set by the PlayerScript.
- Controls: The Buttons for the Player controls (Turning, Menu, etc.)
- Gameplay
- CM behind: The Virtual Camera that places the camera behind the player.
Player Components
- LOD Group: Manages the Object's Visuals depending on Camera Distance.
- NetworkIdentity: A Mirror Networking component that registers the object with the NetworkManager, basically marking an object "unique" in the Network Scene (must never be removed). Is required for PlayerScript.
- NetworkTransform: A Mirror Networking component that tracks the object's position, rotation and scale.
- PlayerScript: All Player Logic
PlayerScript:
(Note: All functions are documented in the code itself. There might be some leftovers from the character creation system, which has been replaced.)
-
playerState: An enum containing the player's state: Moving, Looking at an Object or in UI. Depending on this state, input does different things.
-
string tempName/playerName: tempName is set by the CharacterCreator and playerName is only set when the character is actually spawned in. playerName is a SyncVar, which means that the NetworkManager can control it and is synced over all clients for the object's specific NetworkIdentity, and when the variable is changed
-
OnNameChanged(...): Called from the NetworkManager when the player is spawned in to display the player's name.
-
OnStartLocalPlayer(...): Basically like an "Awake" Method for the local player. Used to collect info from the local CharacterCreator and pass it along to the NetworkManager.
-
CmdSetupPlayer(...): A command, meaning it is send to the NetworkManager which then distributes the info about this specific NetworkIdentity to all other Clients (Basically updates all info send with this function in all other Clients, not in all other local NetworkIdentities)
-
Awake(...): For all connected Clients, so NOT the players, delete all obsolete items (UI, NavMeshAgent, etc)
-
Update(...): Takes care of all input, and reacts to f.e. clicks differently depending on the PlayerState.
-
FixedUpdate(...): Takes care of all frame-dependent movement.
The other methods are used to receive UI inputs over public functions to take care of f.e. turning and loading data from a clicked door.