Copy of Player/AI
Creating A Player
To create a new Player:
Create a new game object and add a Game Agent component.
Go to the inspector of the Game Agent component and check the Is Player checkbox
To check if a specific game agent is the player in code, use the following:
Creating An AI
To create a new AI:
Create a new game object and add a Game Agent component.
Go to the inspector of the Game Agent component and uncheck the 'Is Player' checkbox.
Setting The Starting Vehicle
To make the Game Agent enter a vehicle when the scene starts, drag a vehicle (not a prefab, must be a vehicle in the scene) into the Starting Vehicle field in the inspector.
Getting The Current Vehicle
To get the vehicle that a Game Agent is currently in, use the following code:
Entering/Exiting Vehicles During Gameplay
To enter/exit a vehicle during gameplay, simply call the Game Agent's Enter Vehicle function like so:
If you have a character and you want it to be able to enter/exit a vehicle when in close proximity, see this section.
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.
Accessing Game Agents
To make it as easy as possible to access all the game agents in the scene, the Game Agent Manager component has been provided.
The Game Agent Manager is a singleton class, which means there must only be one in the scene at any time. Just add it to any game object anywhere in the scene.
This component 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.
Provides events for other systems to receive notifications when the player switches vehicles, dies, is revived, etc
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:
Last updated