Unit System
  • WELCOME
    • πŸ‘‹Hello
    • πŸ—ΊοΈRoadmap
    • ⛑️Support & Community
    • πŸŽ“Version - Changelog
  • Getting Started
    • πŸ”ŒImport Package
    • βš™οΈConfiguration
    • πŸ” Database
    • πŸͺŸManager Window
    • Creating a new Scene
      • Player Camera
      • Set up Player
      • Set up Player UI
      • Set up the Game World
    • Create Units
      • Resource (Crystal)
      • Research (Crystal age)
      • Resource node (Crystal Node)
      • Resource collector (Crystal)
      • Combat unit (Mage)
      • Production unit (Mage Tower)
      • Faction (Purple Cubes)
  • How it works
    • Overview
    • Modules
      • Resource
      • Production
      • Population
      • Garrison
      • Collection
  • Integration
    • Unit Selection
    • Unit Formation
    • Object Placement
Powered by GitBook
On this page
  1. Getting Started
  2. Creating a new Scene

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.

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.

Player

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.

      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:

        1. Unit Spawn Radius - spawns units randomly in a radius

        2. Unit Spawn Point - spawns units in a single position

        3. Player Buildings Spawn - 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 singletonPlayersRelationshipManager to it. Without this step, default manager will be created and all other players will be considered enemies.

Selection

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.

If you are using other solutions for selection, you can skip these steps. One option is integration of the Unit Selection package (Unit Selection).

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.

  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.

Interactions

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 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.

Test

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.

  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.

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

PreviousPlayer CameraNextSet up Player UI

Last updated 5 days ago