You can create a unit using the public static method CreateUnit from the UnitManager class:
UnitManager.CreateUnit (Unit unitPrefab, Vector3 spawnPosition, Quaternion spawnRotation, Vector3 gotoPosition, int factionID, Building createdBy, bool free = false, bool updatePopluation = false)
- unitPrefab: The main unit component (Unit) of the unit prefab to spawn.
- spawnPosition: Vector3 that specifies where will the unit will be spawned.
- spawnRotation: Quaternion that specifies the rotation of the unit when it’s created.
- gotoPosition: Vector3 that specifies where the unit will moving to after it’s spawned. If this is the same as the spawnPosition then the unit will not move towards its gotoPosition.
- factionID: Integer that specifies which faction the unit belongs to.
- createdBy: The main building component (Building) of the building that will be marked as the creator of the unit. When set to null, no building creator will be set for the unit.
- freeUnit: Optional field (default value: false). When set to true, the unit will be a free unit (will not belong to any faction).
- updatePopulation: Optional field (default value: true). When set to true, the unit will not affect the faction’s population when it is created.
You can create a placed building using the public static method CreatePlacedInstance from the BuildingManager class:
BuildingManager.CreatePlacedInstance(Building buildingPrefab, Vector3 placementPosition, float yEulerAngle, Border buildingCenter, int factionID, bool placedByDefault = false, bool factionCapital = false)
- buildingPrefab: The main building component (Building) of the building prefab to spawn.
- placementPosition: Vector3 that specifies where the building will be placed.
- yEulerAngle: Float that specifies the building’s euler angle on the y-axis.
- buildingCenter: The Border component of the building that will be set as the center of the building to create. When set to null, no building center will be set for the new building.
- factionID: Integer that specifies which faction the building belongs to.
- placedByDefault: Optional field (default value = false). When set to true, the building will be fully constructed when created. When set to false, builders will have to construct this building before it becomes fully functional.
- factionCapital: Optional field (default value = true). When set to true and the building belongs to a faction, it will marked as the new faction’s capital.
You can create a resource using the public static method CreateResource from the ResourceManager class:
ResourceManager.CreateResource(Resource prefab, Vector3 spawnPosition)
- resourcePrefab: The main resource component (Resource) of the resource prefab to spawn.
- spawnPosition: Vector3 that specifies where the resource will be created at.
Spawning Effect Objects:
You can spawn an effect object using public static method SpawnEffectObj from the EffectObjPool class:
EffectObjPool.SpawnEffectObj(EffectObj prefab, Vector3 spawnPostion, Quaternion spawnRotation, Transform parent = null, bool enableLifeTime = true, bool autoLifeTime = true, float lifeTime = 0.0f)
- prefab: The effect object prefab (that has the EffectObj component attached to it) that you want to spawn.
- spawnPosition: Vector3 that specifies where the effect object will be spawned at.
- spawnRotation: Quaternion that specifies the rotation of the effect object when it spawns.
- parent (optional): If you’d like the effect object to spawn a child object, then assigned the Transform of the parent here, else leave this set to null.
- enableLifeTime (optional): Set to true if you’d like to enable life time as soon as the effect object spawns, else if you’d like to control disabling the effect object from your own components (using the Disable() method from the EffectObj class) then set to false.
- autoLifeTime (optional): Only valid if enableLifeTime is true. Set to true if you’d like to use the default life time assigned in the EffectObj component for the instance of this effect object. Set false otherwise.
- lifeTime (optional): Only valid if enableLifeTime is true & autoLifeTime is false. Set to the custom duration (in seconds) of the effect object life time.