Unity RTS Engine

  1. Home
  2. Unity RTS Engine
  3. Scripting
  4. Useful Scripting Practices

Useful Scripting Practices

Creating Units

You can create a unit using the public static method CreateUnit from the UnitManager class:

Parameters:

  1. unitPrefab: The main unit component (Unit) of the unit prefab to spawn
  2. spawnPosition: Vector3 that specifies where will the unit will be spawned
  3. factionID: Integer that specifies which faction the unit belongs to
  4. 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.
  5. freeUnit: Optional field (default value: false). When set to true, the unit will be a free unit (will not belong to any faction).

Creating Buildings

You can create a placed building using the public static method CreatePlacedInstance from the BuildingManager class:

Parameters:

  1. buildingPrefab: The main building component (Building) of the building prefab to spawn.
  2. placementPosition: Vector3 that specifies where the building will be placed.
  3. 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.
  4. factionID: Integer that specifies which faction the building belongs to.
  5. 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.

Creating Resources:

You can create a resource using the public static method CreateResource from the ResourceManager class:

Parameters:

  1. resourcePrefab: The main resource component (Resource) of the resource prefab to spawn.
  2. spawnPosition: Vector3 that specifies where the resource will be created at.

How can we help?