Setup Border
The Border component can be placed on a building to define a territory occupied by the faction that owns the building. It is useful when you want to limit the placement of certain or all buildings of a faction to its territory and at the same time disallow other factions from placing their buildings on that territory.
1. Configuring Border
We will be adding this component only to the main instance of the tutorial_building in the tutorial_map scene, meaning that we will not be adding it to the actual prefab. Therefore add the Border component to the main object of the tutorial_building instance in the scene. The basic implementation of a border is a circular area around the building it is attached to. For good measure, I have also moved the second faction's default building and unit further away from the player's faction ones.
- Size: Any object within a distance less or equal to the value of this field belongs to the territory defined by the border. For example, set this value to 20.
- Border Prefabs: For this basic implementation of the border, we will use one border object from the demo game. Search for border_object in the project tab and grab the border_object prefab and drag it as an element of this field. You are allowed to have as many representations as you want for the border. For example, one border prefab can be used to visualize the territory defined by the border as a UI element in the minimap and another one can be used to visualize it in the actual terrain where it is visible to the main camera.
Building Limits: The border also allows you to have limitations on building placement inside the territory it defines. For example, we can limit the amount of tutorial_building instances that can be placed inside the border to 3. To do this, add an element to the array in this field:
- Name: Give it a name, for example tutorial_limit.
- Codes: Input the code of the tutorial_building.
- Amount: Assign to 3.
You can also define limits based on full building categories by configuring the Categories field instead of the Codes or use a combination of both. Building placement limits can also be applied on different types of buildings by inputting the different codes of the buildings in the Codes array in the inspector.
However, when configuring the building, we stated that we want it to be placable outside of border/territory which would allow it to avoid the limitations defined here. Therefore, open the tutorial_building and navigate to its building_extension child object where you would find the Building Placer component and disable the Can Place Outside Border field. This is how the Border component now looks post modifications:
2. Testing
Now launch the tutorial_map.
Right off the bat, we can see that the border is now visible in the minimap's camera with the faction's colors.
Now select the units and attempt to place the building outside of this area, that will not be allowed.
Now hold down the Hold And Spawn key (which is defined in the Building Placement Manager) and attempt to place as many buildings as you can inside the faction's territory and as soon as you hit 3, the placement will not be possible anymore.
Download Files
You can download the results of this tutorial here.