My Work on Rise From The Ashes

My Work on the game

As a programmer, it was my job to write scripts for the Unity game using C#. Currently, there are a series of c# scripts for Game Management, unit controller and states, building mechanics and artificial intelligence. There is also code written by the other programmer for buildings, rendering (used for the fog of war), camera controller along with a series of shaders.

View Scripts Folder on Github

Unit Controller

One of the things that are essential to any RTS game is unit stats, unit movement and other unit behaviour. I achieved this by first creating a script to go on each unit called UnitController (Shown on the right.

Each type of unit has individual values for maximum health, movement speed, damage dealt, the time between each attack and an attack range.

Each unit also has a state script attached to it that extends the State class. These handle the different behaviours of each unit using a finite state machine. State scripts get attached and removed from the game object at runtime whenever their state changes through the unit controller, however, a unit can only have one state at a time. At the moment there are 5 main states a unit can have:

  • Idle
  • Moving
  • Flock
  • Follow
  • Patrol

Unit movement

For the unit movement, I originally started making my own steering behaviour classes that have now been archived. The unity navigation mesh is used to calculate the paths and the steering behaviours were used to move between the waypoints on the path. Different steering behaviours were made for seeking, fleeing, and obstacle avoidance along with flocking with the use of boids which included alignment cohesion and separation.

Although the tanks were moving around and stopping when using these scripts I had a difficult time getting each tank in a group to reach its destination without bumping into walls or each other. Sometime they would get stuck altogether. Because of this problem, I reverted back to using nav mesh agents instead which I found to be more reliable.

View Source File

Unit Controller Script
Nav Mesh Agent


A Game Manager prefab was created to go into any scene that had a playable level. Although we have a script call GameManager the prefab is actually divided up into several managers for different purposes these include the following

  • Unit Manager
  • Selection Manager
  • Formation Manager
  • Resource Manager
  • Building Manager (Created by George)
  • Music Manager (Created by George)

Game Manager

This script contains the main game loop including win, lose and paused states using a GameState enum. It ends the game when either of the headquarter building placed on the script has been destroyed and causes the dialogs to appear when the game is not currently in the running state. Information about the player and enemy's maximum resources and maximum unit count are also stored here.

There are also 3 different custom cursors for the default cursor the move cursor and the attack cursor which change when the player clicks on the action buttons.

View Source File

Unit Selection

Selection Manager

This script allows the player to select a unit using the mouse. They can select an individual unit by clicking on one of the vehicles or select multiple units by either clicking and dragging or by holding down the shift key when clicking on multiple vehicles one after another. If the player click's on something that is not a unit they all get removed from the selection. Selected units are shown through the white border that appears around them.

View Source File

Selection Manager
Units moving on right-click

Unit Manager

This script controls the movement of selected units from one part of the map to another. If the player right-clicks on a game object that is on the ground layer the units will move that point. If the player right-clicks on an object that is on an enemy layer the selected unit will follow that enemy and then attack when they are in attack range.

View Source File

Unit Manager
Unit Formations

Formation Manager

This script controls where exactly each unit ends up after they have moved to a given location. Formation are also created when each vehicle first leaves the vehicle bay and moves to the rally point.

To ensure that they do not all fight over the exact same spot and bump into each other the needs to be some space in between each unit. This is done by constructing a grid around the centre point. In the image above The green wire sphere shown on the gizmos shows the location that each unit must end up.

View Source File

Formation Manager

Resource Manager

This script controls how many resources both the human player and the a.i. player has. Both players have a starting amount, maximum amount and current amount of steel. The maximum amount can be increased when certain buildings are built. Resources get generated through a script called Resource Building which is attached to building prefabs that generate them. The resource building then invokes a function on the resource manager to increase the steel count of the player who owns that building.

View Source File

Resource Manager script attached to game manager


Resource Building

This script is used to generate a chosen resource at runtime as long as the building still exists in the scene. if the building increases the maximum resource quantity when constructed the "max quantity increase" variable is used to update the maximum in the resource manager.

During a specified time interval (in seconds) the player's resource of the given type increases by the "quantity to add". There is also the option to give the resources to the A.I. player by having the checkbox checked.

View Source File

Resource Building
Floating Resource Label

Floating Resource Label

The building prefab also has a floating-label game object with an icon with text next to it that shows the player how many resources they just gained. The rising speed, fade in speed and time in which the label stays before disappearing can all be adjusted.

View Source File

Resource Gaining


Unit Gui

This script controls what panels appear on the user interface whenever one or more units are selected along with what the panels display inside them. If the player clicks on the move, attack, halt or set rally point buttons, the functions that handled the clicks are invoked on this script.

If the player selects one unit then the unit GUI receives information about and displays the icon along with its stats as shown below.

Unit Stats

If multiple units are selected then a series of icons get populated along the selection panel, one for each unit in the selection. Each icon contains an image for the type of unit with its current health underneath.

Multiple unit selection
UnitGui script component


In order for the player to play Rise from the Ashes as a single player there needed to be some form of artificial intelligence. There was already A.I. built into the units with the finite state machine and the logic that made them automatically transition between the states when certain conditions are met. However in order to get a proper opponent an actual AI player needed to be created. So I created a new script called Ai Player for this purpose.

Ai Player

This script required a lot of things to be attached to it in order to be set up. It first needed a reference of the player's base so that it knows where to dispatch the units. It then has a rally point where it sends each unit after it finishes training them from one of the Vehicle bays.

Every time the A.I. constructs a vehicle bay it gets added to the vehicle bay list. The user can also set up pre-built vehicle bays and drag them into the list before the game runs. This enables the A.I. player to know what vehicle bays they own and how many of them are available.

There is also the option of setting up a patrol route that the A.I. player can send their units around by creating waypoints that the user drags into the "Patrol Route" list.

View Source File

A.I. Player (new)

Ai Task & Task Schedule

This area is where all of the main decisions and strategies of the A.I. player take place. This is done by creating a series of task sets that run in parallel where each task sets contain a series of AI tasks. Each task will automatically get sorted in order of priority as soon as the game starts. If the A.I. successfully completes an AI task it then moves down to the next element in the task set.

Each task set can either be executed once and then all tasks complete it stops, or the loops task set option can be checked which brings it back to the first task. There is also an option to "Add rebuild tasks" which means that as soon as the player destroyed an AI player-controlled building, a new build task for that building will get added to that task set.

In order to create the individual objects for Ai Tasks used Unity's scriptable object class. The main class was called AiTask and which has specific types of tasks extending the class.

View Source File


Scriptable Objects

AI Task

This is an abstract class that serves as the parent class for all of the specific types of Ai Tasks. All scriptable objects that go in a task set are of type AiTask. AiTask does not have a menu item and so only scriptable objects of its subtypes can be created.

There is a variable called Time Delay that all subclasses inherit and what this does is add a time delay before beginning the task once all of the conditions to complete it have been met. The reason for this is to make the AI player play the game more slowly to allow different levels of difficulty for the human player.

View Source File

Build Task

This scriptable object class enables the AI player to construct a building. If the next task on the list is a "Build Task" and the AI player has enough steel to construct. The construction task will begin

The prefab of the building that will appear in the level is dragged into the "Building To Construct". Each build task is given a priority score so that when a building gets destroyed and the AI adds a rebuild task the build tasks get sorted in order of priority.

View Source File

Build Task

Train Unit Task

This task enables the A.I. player to construct a vehicle unit from one of the vehicle bays in their base. If the AI player does not own any fully built vehicle bays then they will not be able to complete the task. The vehicle bay also cannot already be training another unit.

The vehicle bay used to train the unit is selected from the Vehicle Bays list in the Ai Player script. it will check the first vehicle bay in the list and if that is busy, it will check the second one, then the third and so forth. If there are none available the AI player will wait until there are.

The AI unit prefab for this task is placed in the "Unit to Train" placeholder on the "Train Unit Task" scriptable object as shown on the right.

View Source File

Train Unit Task

Dispatch Wave Task

This task allows you to set a wave of units for which the AI player will send from their base to the human player's base so that they can attack it. Unlike build tasks and train unit tasks, a dispatch wave task does not require any steel to be completed. Instead what will be checked for each frame is whether they currently own all of the units necessary for the attack wave.

A list of enemy types is created in an Enemy Wave array as shown on the right. In each element, a type of unit is selected from the "Type" drop-down and the number of units of the specified type is inserted next to "Quantity".

Once this task is completed vehicles will move across the map to the location set as the player base in the Ai Player script.

View Source File

Dispatch Wave Task

Game Options

game options

This script adjusts the game options from the main menu and the pause menu from inside the game. I started off with the GameOptions script that I wrote for Toy Takeover before making modifications to it.

There are 3 main sections of game options Video/Audio, Graphics and gameplay options. As soon as the value changes on any of the GUI components, a function is invoked from the GameOptions script. When save changes is clicked a function is invoked that saves all of the values to the play prefs.

All of the GUI components are placed onto the Game Options script so that they update from the player prefs once the screen is loaded.


Leave a Reply