Game Agents

To give you the greatest flexibility with designing your game, the player and AI are separated from the vehicles that they control, enabling them to switch vehicles seamlessly during gameplay.
The GameAgent component represents either a player or AI that can take control of different vehicles, be killed, be revived, and belong to a Team.

Creating A Game Agent

To create a new player or AI, simply create a new game object and add a GameAgent component.

Creating A Player

To make the Game Agent a player, simply check the 'Is Player' checkbox in the inspector of the GameAgent component.

Creating AI/NPCs

To make the Game Agent an AI/NPC, simply uncheck the 'Is Player' checkbox in the inspector of the GameAgent component.

Setting The Starting Vehicle

To make the Game Agent enter a vehicle when the scene starts, simply drag a vehicle (not a prefab, must be a vehicle in the scene) into the 'Starting Vehicle' field in the inspector of the GameAgent component.

Entering/Exiting Vehicles During Gameplay

To enter a new vehicle during gameplay, simply call the Game Agent's EnterVehicle function:
// Enter a vehicle
myGameAgent.EnterVehicle(myVehicle);
// Exit vehicle
myGameAgent.EnterVehicle(null);

Killing/Reviving Game Agents

Game Agents are automatically killed when the vehicle they are in is destroyed.
Here are examples for how to use the relevant functions:
// Kill the game agent
myGameAgent.Kill();
// Revive the game agent
myGameAgent.Revive();
// Run some code if the game agent is dead
if (myGameAgent.isDead)
{
// Some code
}

Accessing Game Agents

To make it as easy as possible to create a scene for your game, the GameAgentManager component has been provided which does several key things:
  • Stores all the Game Agents in the scene for easy access
  • Stores a reference to the 'Focused Game Agent' which provides a single reference point to the player for things like camera following, rumble effects, etc (it can be an AI too, if desired).
  • Provides events for other systems to receive notifications when the player switches vehicles, dies, is revived, etc
The GameAgentManager is a singleton class, which means there must only be one in the scene at any time.
All you need to do is add the component anywhere in the scene and other scripts can find it using the static GameAgentManager.Instance reference, for example to access the Game Agents in the scene:
// Get a list of all the game agents in the scene
List<GameAgent> gameAgentsInScene = GameAgentManager.Instance.GameAgents;