The Chase - Car Chasing Game
Introduction
If you are here, that means you own or you are interested in one of my assets: The Chase - Car Chasing game and I thank you for that!
Installation
Before installing / importing the asset inside your Unity project first download and import another asset which this project uses: 4 Low Poly Toon Cars. It’s totally free small (only 1.1MB) which contains car models. After that you can download and install The Chase asset in Unity and that’s it.
Hierarchy
The source of asset is inside: Assets/hardartcore/TheChase folder. You can find every material, model, script or UI sprite & texture used in the project there.
Animations folder
Inside Animations folder there is only one folder with animations for the Bomb object used in the project.
Fonts folder
Fonts folder contains all variations of Montserrat font. Link to the font: Google fonts and the License.
Materials folder
All materials can be found here.
Models folder
All models (FBX files) can be found here. Inside Models/Maps/ folder you can find all fbx files which are used in Map01 (level 01) and Map02, mostly trees, rocks, grasses and etc.
Prefabs folder
All prefabs can be found here: Cars, Collectables, Cops, Maps, VFX.
Scenes folder
There are two scenes in this project: InitialScene and MainScene . Initialscene - is the one which the user see first where he can choose (buy) the car, the map and start the game. MainScene - is the one where the actual gameplay happens (where the cops are chasing you because … why not).
ScriptableObjects folder
Inside Cars / Maps folders you can find all available maps & cars inside the game. In order to use a car in this project first you have to create it as a Scriptable object and then customize it’s values as you want.
Scripts folder
This is where the source code of every script lies. Simply by looking every folder’s name you can easily see what scripts are placed in it.
- Controllers - Car & Cop AI controllers
- Editor - Useful editor scripts
- Managers - All scripts which “Manages” something
- Objects - Coins, Bombs, Magnet and etc
- ScriptableObejcts - Car & Map SO
- UI - UI related scripts
- Utils - Extensions and Utils classes
Settings folder
Settings files are placed here: URP Settings & Main Input Controls
Shaders folder
A single shader file: GradientShaderGraph
Sounds folder
All sounds files are placed here: button click, explosions and etc.
Sprites folder
All icons used as UI elements are placed here.
Textures folder
All textures used in Materials are placed here.
And that’s it! :)
InitialScene
The InitialScene is the first scene which is loaded when the game is started on user’s device. Here the user can select or buy a car, select a different map to play, change sound settings & reset it’s progress from Settings dialog.
This is how the scene’s hierarchy looks like ->
MainCanvas
MainCanvas holds the main UI of the game
The main script which holds all the data here is MainMenuUi.cs.
Buttons section hold a reference to all buttons inside the MainCanvas. All click listeners are set via the script so no way you can forgot to assign something inside the Editor and it does not work.
Panels section hold a reference to Settings dialog and SelectionPanel.
CarParent is a Transform from the scene which holds the selected car model. When the user select a new car the new model / prefab is instantiated and set as a child of this transform.
Maps list holds a reference to the preview GameObjects of every map available inside the game. The previews are placed under Environment GameObject.
SkyBoxMaterials holds a reference to different skybox materials which are changed once the user selects a new map. Every map (level) has it’s own skybox material with different gradient colors.
SettingsDialog
SettingsDialog holds as you probably guess….the settings - yes!
There is only three buttons here:
- Close button - which close the dialog
- Music button - which toggles music on\off.
- Reset Progress button - which opens Reset Progress dialog.
ResetDialog
Reset dialog as you guess again lets the user to reset his/her progress.
It’s quiet simple. Two buttons:
- Cancel button - Closes the dialog without resetting user’s progress.
- Yes button - Resets the user’s progress (Clear PlayerPrefs in our case).
SelectionPanel
Selection panel let’s the user to choose a different car or map.
It’s quiet simple setup too. We have a few buttons:
- Next button - Choose next car or map based on which button we selected (Car or Map)
- Previous button - Choose the previous car or map.
- Select button - Which confirms user’s selected car or map (save it in PlayerPrefs).
- Unlock button - Unlock or buy the current car if it’s locked and the user has enough coins to purchase it.
- Close button - Close Selection panel and reset selected car or map if nothing is selected via pressing Select button.
SceneLoadingManager
SceneLoadingManager is responsible for showing an animation while loading from InitialScene -> MainScene.
Managers
CarsManager , MapManager , CurrencyManager, SoundManager as you can guess holds the references to cars , maps, currency (coins) and used sounds inside the game.
MainScene
The MainScene is where the actual game is played by the user.
The most important thing here is to understand what is the purpose of UpdateManager script and how the whole map is generated.
UpdateManager
The idea behind the UpdateManager script is to combine all Update calls into one script. Here is a link to blog post from Unity about this technique: BLOG . So basically we have a BaseBehaviour class which is used by all other dynamically created objects which overrides Update method for some calculations. And instead of calling Update in every class, this is done by UpdateManager and every created objects is added to a list which the manager is using to update all items. Simple as that! : )
Map Generation
Map (or level) is generated using Tile objects. Every tile object has GameObjects as children (trees, rocks and etc) and a Tile script attached to it. The Tile scripts has a few serialized fields: coin positions & abilities. As you probably guess Transform[] coinPositions are used to load coins at given transform. Abilities[] abilities array is used to show randomly an available ability based on some random calculations. Let’s say you want some tiles to show only MAGNET abilities and others only FUEL_TANK. You can achieve this by updating this array.
The Map is generated using this order:
Once the GameManager initialize it’s variables and state inside InitVariables()
calls -> MapManager.Instance.LoadSelectedMap();
which finds which is the latest selected map by the user and pass that value to the TilesSpawnManager -> TileSpawnManager.Instance.InitMap(selectedMap);
and this is where the all Tiles objects are created and loaded. And once this process is done every tile object loads and initialize it’s coins and abilities. And that’s it.
Customization
Create a new Car
Every car object in the project is represented using a Scriptable Object.
- In order to create a new car first you will have to create a new CarScriptableObject using the menu -> Right Mouse Click -> Create -> The Chase -> Create -> Car .
This will create a new empty CarScriptableObject.
- Once this is done, create a new empty GameObject in your scene and attach a Car script and BoxCollider to it. Once this is done, add a car prefab as a child to the empty object you created and than properly update the BoxCollider’s size to match the car’s size.
- Then you can attach Smoke & Skidmarks prefabs from Assets/hardartcore/TheChase/Prefabs/VFX folder and assign them to the Car script.
- And then assign that prefab to the newly created CarScriptableObject as CarPrefab value.
- Add the CarScriptableObject to the list of CarsManager in InitialScene and you are good to go.
Create a new Map
Create a new MapScriptableObject using the same menu as when we were creating a Car.
Create a Tile GameObject (a simple Plane for example with material attached to it) and put some trees and rocks on it. Add Tile script and BoxCollider. Once that’s done you can setup some Coins Positions and Abilities.
Save the object as Prefab and add it to MapScriptableObject’s Tile Prefabs array.
Add the new Map to MapManager in InitialScene and do not forget to add a new preview under Environment Gameobject in InitialScene too since the SelectionPanel uses those previews while letting the user to select a new map.
And that’s it.