Add the Building component to the main building object and configure the building from the inspector.
Building General Settings:
- Building Name: The name that will be displayed when the building is selected.
- Building Code: Assign a unique code for each building which the system will use to identify the building.
- Building Category: The category that this building belongs to.
- Building Description: A description for the building that will be displayed when the building is selected.
- Building Icon: An icon for the building that will be displayed when the building is selected.
- Free Building: If true, then this building will not belong to any faction.
- Can Be Attacked: If false, then this building will be immune to attacks from units.
- Task Panel Category: When using categories in the task panel (check the UI Manager documentation), this is the ID of the task panel that this building belongs to when it appears while selecting builder(s). Task Panel categories allow to organize tasks based on a criteria that you can decide.
- Minimum Center Distance: The minimum distance between this building and any building center (a building center is a building that has the border component, explained even more in the next part).
- Force Minimum Distance On Player? If this is enabled then the local player will also have to respect the distance chosen in the above field when placing this building in the game. However if this is disabled then this only applies for NPC players.
- Building Radius: This is the radius of the building that units use to interact with the building (when the building is selected in scene view, a blue gizmo sphere will appear in the scene view displaying the radius). Make sure that the radius is bigger than the Navigation Mesh Obstacle component size so that units can successfully interact with the building.
- Faction ID: If this building comes ready with the map (for example, the capital building must always be present in the scene when creating it). Then you must assign the faction ID manually. If not, leave this empty.
- Placed By Default: Choose whether the building is placed at default (will appear fully built when the game starts) or if it requires builders to build it. This also applies to buildings that you want them to be pre-existing in the map.
- Population Slots To Add: A building can increase the maximum population amount for a faction by setting this field to the amount that it adds.
Building Resource Settings:
- Building Resources: How much resources does it cost the faction to place this building? Enter the name and the amount of the resource that this building needs to be built.
- Bonus Resources: A building can affect how fast units could collect resources in its area (its area is determined by the size of the border that belongs to the nearest building center). For example, to increase collecting Food resources, you would just type: “Food” in the Name field. And then type how much you need to increase its collection per second in the Add Collect Amount Per Second field.
- Is Resource Drop Off: Choose whether you want resource collectors drop off their resources at this building or not. This option is not needed when you choose resources to be automatically added to the faction while collecting (See the resources section for more information about resource collection methods). When enabled, this option will show a list of other options regarding the resource drop off process:
- Drop Off Position (optional): In case you want to use a static drop off position, you can use a child object of the building as the drop off position (use example: this building is a warehouse where units can drop off resources and you only want units to drop resources at the warehouse door). When this is not assigned, the unit will simply move towards the building and once in range of the building the unit will drop the resources off.
- Accept All Resources: When enabled, the building will act as a drop off building for all types of resources. When disabled, the “Accepted Resources” array should appear in the inspector in which you can enter the names of the resources that the building will accept.
- Place Near Resource: When disabled, the building can be placed anywhere depending on the other settings. Once this option is enabled, you’d need to a resource type name and the allowed range to that resource type at which the building can be placed. This is useful in the case where you want to place a certain resource type warehouse near the resource only.
Building Health Settings:
- Maximum Building Health: Maximum health points for this building.
- Minimum Health To Launch Task: Minimum health points required for this building to be able to launch tasks (Building tasks are explained right in the next part).
- Hover Health Bar Height: When moving the mouse over a building’s object, a health bar would appear. This is the health bar’s position on the y axis.
- Building States: Depending the building’s health, you can show and/or hide parts of the building (such as fire particle effects or smoke when the building is badly damaged). Therefore, you need to create an empty object and make it a child object of the main building’s object. Then drag and drop this object into the “Building States Parent Obj” field. All the building states objects must be children of that object. You can have as many building states as you need. For each building state, you must assign an interval of health (“Min Health” and “Max Health” at which this building state is active. You must also assign which objects will be shown (“Parts To Show”) and which ones will be hidden (“Parts To Hide”) when the building state is active (when the health is inside the specified interval). When a building moves to another state, the last parts that were shown will be hidden and the parts that were hidden will be shown.
- Building Destruction: When the building’s health is 0. The building will be destroyed. This destruction can be improved by assigning an audio clip in the “Destruction Audio Effect” that will be played and assigning a “Destruction Object” that will be spawned when the building is destroyed.
- Destroy Award: This array allows the faction that destroyed this building to get resources as a reward. The resource types and their respective amounts can be assigned inside this array.
Building Upgrade Settings:
- Upgrade Building Directly: If false, the player won’t be able to upgrade this building directly.
- Upgrade Building: The target building to upgrade to.
- Building Upgrade Resources: The resources required to upgrade this building.
- Upgrade Required Buildings: The buildings that must be spawned to launch this upgrade.
- Building Upgrade Duration: Time required to complete the building’s upgrade.
- Upgrade All Buildings: If true, then this upgrade will trigger all upgrades on other buildings (even the ones that can not be upgraded directly).
- Max Simultaneous Tasks: The maximum amount of the tasks that can be run at the same time.
- Building’s Tasks: First set the amount of the building’s tasks by changing the size of the “Building Tasks List”. And for each task, assign:
- Faction Specific: If the task is faction type specific, then set this to true.
- Faction Code: If the task is faction type specific, then set the code of the faction where this task is available.
- Task Description: A short description for the task that will appear when the player’s mouse is over the task icon.
- Task Type:
- Unit Creation: produce units
- Destroy: building self-destruction
- Research: apply changes to units attributes
- Task Panel Category: When using categories in the task panel (check the UI Manager documentation), this is the ID of the task panel that this task belongs to when it appears while selecting this building and displaying its tasks. Task Panel categories allow to organize tasks based on a criteria that you can decide.
- Upgrade Task Panel Category: Same thing above but for upgrades for this task (because they do appear as a separated task).
- Task Icon: The icon that will appear in the building’s task panel.
- Required Resources: Which resources and how much of these resources does the task need.
- For the “Unit Creation” task type: Assign the unit’s prefab that will be created in the “Unit Prefab” field.
- For the “Research” task type: Set the units that you want to be affected by this research task (simply drag and drop units into the “Unit List” array) then set the values that you want to change (either positively or negatively). Values that can be affected are currently: Speed, Unit Damage and Building Damage.
- Reload Time: How long does this task take to take effect?
- Task Completed Audio: Audio clip played when the task is done.
- Task Upgrades: Each “Unit Creation” task can have multiple upgrades. This means that the player can launch an upgrade task in order to change the effect of one of the tasks and make it produce another unit. In order to create upgrades for a task, set the amount of the “Upgrades” array of this task (you can have as many upgrades for each task as you want):
- Target Unit: The Unit prefab that will be produced when the upgrade takes effect.
- Upgrade Resources: Which resources are required to apply this upgrade.
- Upgrade Icon: The icon of the upgrade task that will appear in the “Task Panel” when the building is selected.
- New Task Icon: The new icon of this task after the upgrade.
- Upgrade Description: A short description for the upgrade task that will appear when the player’s mouse is over the upgrade task’s icon.
- New Task Description: The new description of this task after the upgrade.
- New Task Resources: The required resources of this task after the upgrade.
- Upgrade Reload: The time needed in order for this upgrade to take effect.
- New Reload Time: The new reload time for this task after the upgrade.
- When an upgrade is applied in one building, it will be also applied in all buildings of the same type.
- Handling building tasks in game (launching them, canceling them, etc..) is explained in the UI part of the documentation.
- Building Model: Drag and drop the building’s model object in this field (it must be a child object of the main building prefab).
- Building Plane: This is the object that hold the selection texture and which will be activated when the building is selected. This object includes a mesh renderer as it will be colored in the faction’s color when activated. Also a child object of the main building’s object and has “Building” as its layer.
- Building Selection Component: The selection collider must not be the same as the building’s main collider. Therefore, create a new empty object and make it child of the main building’s object. Then add a Collider to this object (with “Is Trigger” set to true). This collider represents where the player has to click with the mouse in order to select the building and also acts as hitbox for attack objects. Finally, add the SelectionObj component to the selection object and drag and drop this object to the “Building Selection Component” field in the Building component, the SelectionObj component has the following fields
- Obj Type: Set to Building.
- Minimap Icon Size: Represents the size of the minimap icon for this building.
- Construction Object/States: When the building is being built, you have two options: You can either display one static object from the beginning till the end of the construction and that is the “Construction Obj”, or you can change the displayed object of the building under construction depending on its current health to show the progress of the construction:
- Construction Obj: Being a child object of the building’s parent object, this object will be shown when the building’s is getting built for the first time. The rest of the building’s model will be hidden till the building is completely built (reaches maximum health). Make sure that this object has the “Default” layer and the “Building” layer.
- Construction States: For each state set the object that you want to display (that object must be a child of the building’s parent object and make sure it has the “Default” layer. Then set the health interval at which you want this object to be displayed at.
- Building Damage Effect: An object that will be spawned each time the building receives a damage. This object must have the EffectObj component. For more information about effect objects and how to create them, check out this documentation page.
- Units Spawn Position: For buildings that can produce units. A position for spawning units must be chosen. Therefore, create a new child object of the building, assign the “Building” layer to it, place it wherever you want the units to appear at when they are created. And drag and drop that object into this field.
- Units Goto Position: When the units spawn at their spawn position, you can assign a goto position to them meaning that as soon as they spawn, they will move to the goto position. Create a new child object of the building, assign the “Building” layer to it, place it wherever you want the units to go to after they spawn. And drag and drop that object into this field. You can also assign a model for this object which will appear in game when the building is selected. Right clicking on any free part of the terrain when selecting a building that has a goto transform assigned, will set the goto position to where the player has clicked allowing the player to change the goto position in game.
- Faction Color Objects: Drop and drag objects that have a “Mesh Renderer” or a “Skinned Mesh Renderer” component that are children of the main building object and that you want to color their mesh with the color of the faction. For each one, specify the ID of the material that you want to color.
- Selection Sound Effect: Audio clip played when the player selects this building.
- Launch Task Sound Effect: Audio clip played when a task is successfully launched.
- Declined Task Sound Effect: Audio clip played when a task can not be launched for any reason (insufficient resources, etc..).
Right after creating the building, drag it to the project and create its prefab.