> For the complete documentation index, see [llms.txt](https://travljen.gitbook.io/unit-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://travljen.gitbook.io/unit-system/getting-started/creating-a-new-scene/set-up-player.md).

# Set up Player

When you are starting with an empty scene, here are a few things steps you will need to make things work for the Player out of the box.&#x20;

As mentioned in the first page, these steps can be guided and simplified with Editor window that can be found under **Unity menu → Tools/TRavljen/Scene Wizard**.

First we will add **player**, then **unit selection** and finally **interaction logic**.

<details>

<summary>Player</summary>

Start by drag & dropping a **Player** prefab into the scene.

1. Set the **Faction** on the **Player** component. This defines the faction attributes of the player, like available starting units, resource and research, limitations, etc.
   1. Add modules on the player. If you are using all the provided functionality simply add all of them and configure their properties. *Hold mouse over each property to see more information about.*
   2. Configure spawning on start:
      1. If you are using provided prefab it will also contain a **Faction Player Unit Spawner** script for spawning start units from the player's faction and you can go ahead and **configure it** to your liking (position, radius, etc.).
      2. Even if using a custom player script, you may add **Faction Player Unit Spawner** manually or handle spawning of player's starting units on your own.&#x20;
      3. When adding **Faction Player Unit Spawner** manually you will also need to add two other components, one for spawning moving units and one for spawning static units (buildings). Few of the provided options would be:&#x20;
         1. <mark style="color:purple;">**Unit Spawn Radius**</mark> - spawns units randomly in a radius
         2. <mark style="color:purple;">**Unit Spawn Point**</mark> - spawns units in a single position
         3. <mark style="color:purple;">**Player Buildings Spawn**</mark> - places buildable units with a pre-defined positions
         4. Or create your own scripts by implementing the required interfaces.
   3. **Player Relations** - If you implemented custom `APlayer` script & relations management, you can skip this step. Otherwise create an empty object an attach singleton`PlayersRelationshipManager` to it. Without this step, default manager will be created and all other players will be considered enemies.

</details>

<details>

<summary>Selection</summary>

Now that you have player and his camera set up. We can add selection logic for the player. This guide uses **demonstration scripts** which you can tailor to your own needs, as they are not part of package implementation.&#x20;

If you are using other solutions for selection, you can **skip these steps.** One option is integration of the **Unit Selection package** ([Unit Selection](/unit-system/integration/unit-selection.md)).

Find **Player Selection** prefab, then **Drag & Drop** it under the player game object. *The hierarchy is not required, but this way all the references will be automatically set.*&#x20;

1. Configure properties of the `EntitySelector` component.
   1. Set **Selection & Ground** layers for Raycast detection, by default all layers are used.
2. `EntitySelectionManager` does not require configuration, but you may listen to the events on it.

</details>

<details>

<summary>Interactions</summary>

Selection itself doesn't allow control of the units. Now you need to add interaction logic for the selected entities.

Find **Player Interactions** prefab, then **Drag & Drop** it under the player game object. *The hierarchy is not required, but this way all the references will be automatically set.*

1. `EntityPlacementSpawnControl` listens to the mentioned `OnEntityPlacementReady` event and performs unit spawning with a building spawner, like the provided building spawner with pre-defined static positions. This may also be replaced with other placement solutions like [Object Placement](/unit-system/integration/object-placement.md) package, which is a complete solution for placing an object in world space.
2. `TargetedUnitInteractions` component implements basic interaction expectations. When a unit is selected, it may be interacting with another entity, moved to a new position or place multiple units in formation. Configure to your projects needs:
   1. Set **Interaction Key** for invoking interaction (by default right mouse button).
   2. Set **Selection & Ground** layers for Raycast detection, by default all layers are used.

</details>

<details>

<summary>Test</summary>

Once you have Camera, Player, Selection and Interactions you should be able to start the scene and test this in action. If you are using **demonstration prefabs** you can follow the next steps to test it all out.&#x20;

1. Assign the player **Blue Cubes** faction, so that the expected **worker** is spawned which will be responsible for building other units.
2. Next **Select spawned worker** (left mouse button) and use **interaction key** (right mouse button) on ground to move the worker around the terrain.
3. With **worker selected** you can also invoke **shortcut actions** like construction. When worker is selected you can use shortcut keys on its production actions to invoke them without UI. **F1** will start placement of **Town Hall**.

</details>

Now that you can spawn initial units of the player and control them. It's time to provide some UI elements for the player.
