Production unit (Mage Tower)
Last updated
Last updated
There are few ways to give the player access to the new resource.
Unit's Passive Resource Production - Supports constant production of a resource
Unit's Active Production - Supports production of any producible object (resource, research, unit, etc.)
Resource Node - Supports collectors to gather resource, either from node (entity) or structure (unit), like praying on temple structure for god's favour.
Or you limit the player and only give him initial resource, no option to collect new.
In previous tutorials we already covered the resource node and combat unit. Now we will create a Mage Tower that will produce Crystals passively and produce Mages actively.
To create new production unit we must again first create a AUnitSO
data set with capabilities, before we create a prefab.
Open up the UnitSystem window and proceed with the steps:
Select Unit type
Click Create New button
Set desired name and description of the new unit
Set cost of the unit, resources player must consume to produce/place this unit
Set requirements research or other producible if applicable, like the new Crystal Age research.
Set production attributes like Population Capacity if this structure should increase housing of units. Additionally you can create new Unit Limit attribute which specify a Mage unit, this functionality limits player's max number of mages and each tower could increase the limit for X amount.
Select Capabilities tab
Add Health capability so that unit may be destroyed by enemy units.
Add Buildable capability which enables the unit to be constructed before it becomes operational.
Add Passive Resource Production capability and set production resource with its quantity produced per second.
Add Active Production capability for production of Mage units.
Here you can add support for the unit to produce any producible you have available.
After data asset is created, we can proceed with creating a Unit prefab:
Click on the Create Prefab button if you wish for prefab to be created automatically.
Now click Open Prefab to and open Scene window to see it. You should see 5 components already present (Unit, Health, UnitBuilding, UnitPassiveProduction and UnitProduction).
Configure visuals as desired, by default a primitive cube model is present.
Add collider & layer to the root game object, primarily for selection and projectile collisions.
Optional
In case this unit will produce and spawn other units (like mage) then you should configure the default UnitSpawnPoint
attached by default. This spawn point can be removed and replace with a custom IUnitSpawn
.
Manage object as obstacle on navigation path.
If you are using Unity's NavMesh system, you can add NavMeshObstacle
component to define where navigation is not possible once building unit is placed.
Additionally attach the BuildingUnitNavMeshManager
component, this will toggle on/off obstacles and agents while unit is building respectively.
If you are using a different navigation system, add it's obstacle component and create a new script to listen for events on UnitBuilding
component where you can toggle your components on/off. See BuildingUnitNavMeshManager
for example.
Add building animation:
If you wish to use provided component add RaiseBuildingAnimation
, set it's reference to the animated transform and start offset which will simply move the transform from offset back to Vector3.zero
while building the unit.
Or you can implement your own animations for building unit, by creating a component which derives from ABuildingAnimation
class.
For pre-defined interaction positions use the StaticInteractionPositionProvider
component.
Select shape
Define shape size
Specify unit spacing
Unit Selection - Integration; If you are using Unit selection package for selecting units, check out the Unit Selection page for more information.
If you are using an existing faction for testing this new unit, you can open it up or to create new faction with steps here Faction (Purple Cubes).
Then add the unit to default actions of the faction. These actions will be presented in demo scene when any unit that has Builder capability is selected.