Class PlayerSelector
Centralized manager responsible for selecting and initializing the player entity, camera, and UI components.
[DisallowMultipleComponent]
public class PlayerSelector : MonoBehaviour, IPlayerSelectorService, IUnityGameService
Inheritance
Implements
Remarks
This class serves as a hub for player-related configurations:
- Allows designers to specify which player controllable, camera, and UI to spawn via the Unity Inspector.
- Automatically registers PlayerController?text=player+controllers present in the scene.
- Provides a centralized access point for other components to interact with the active player controller.
Methods
FindStartingPoint()
Retrieves the GameObjects tagged with the "StartPosition" tag.
public Transform FindStartingPoint()
Returns
Transform — Returns starting point's transform, or null if no StartingPoint is found.
GetPlayerControllerIndex(PlayerController)
Get player index matching the given player controller
public int GetPlayerControllerIndex(PlayerController playercontroller)
Parameters
| Name | Type | Description |
|---|---|---|
playercontroller | PlayerController |
Returns
int — Index of the player controller if found. Otherwise, return -1;
GetPlayerTransform()
Gets the Transform of the first player controller.
public Transform GetPlayerTransform()
Returns
Transform — The Transform of the player controller if found; otherwise, null.
RegisterPlayerController(PlayerController)
Register player controller
public void RegisterPlayerController(PlayerController playercontroller)
Parameters
| Name | Type | Description |
|---|---|---|
playercontroller | PlayerController |
TryGetPlayerController(int, out PlayerController)
it will attempt to get player controller given the player index
public bool TryGetPlayerController(int index, out PlayerController playerController)
Parameters
| Name | Type | Description |
|---|---|---|
index | int | |
playerController | PlayerController |
Returns
bool — true:There is a player controller matching the player index false:No player controller with given index
TryGetPlayerTransform(out Transform)
Attempts to get the Transform of the first player controller.
public bool TryGetPlayerTransform(out Transform transform)
Parameters
| Name | Type | Description |
|---|---|---|
transform | Transform | When this method returns, contains the Transform of the player controller if found; otherwise, null. |
Returns
bool — true if the player transform was found; otherwise, false.
UnRegisterPlayerController(PlayerController)
Unregister the player controller
public void UnRegisterPlayerController(PlayerController playercontroller)
Parameters
| Name | Type | Description |
|---|---|---|
playercontroller | PlayerController |