Battle City in Unity Part 24 : Bonus Crates - Level Up
This article is Part 24 in a 25-Part Series.
- Introduction - Battle City in Unity Prequel
- Part 1 - Battle City in Unity Part l: Single(ton) Sole Survivor
- Part 2 - Battle City in Unity Part 2: Level Creation using Tilemaps
- Part 3 - Battle City in Unity Part 3: Creation of the Protagonist and Antagonists(Tanks)
- Part 4 - Battle City in Unity Part 4: Tank Movement
- Part 5 - Battle City in Unity Part 5: Player Controller
- Part 6 - Battle City in Unity Part 6: Enemy AI
- Part 7 - Battle City in Unity Part 7: Creating Projectiles
- Part 8 - Battle City in Unity Part 8: Hurting the tanks
- Part 9 - Battle City in Unity Part 9: Firing the shots
- Part 10 - Battle City in Unity Part 10: The Spawn
- Part 11 - Battle City in Unity Part 11 : The Gamemaker - Starting the Stage and Game Over
- Part 12 - Battle City in Unity Part 12 : Level Manager
- Part 13 - Battle City in Unity Part 13 : The Gamemaker - Spawning
- Part 14 - Battle City in Unity Part 14 : The Gamemaker - Stage Cleared or Game Over
- Part 15 - Battle City in Unity Part 15 : Spawning Invincibility
- Part 16 - Battle City in Unity Part 16 : Exploding Tank animation
- Part 17 - Battle City in Unity Part 17 : Score Calculation
- Part 18 - Battle City in Unity Part 18 : Battle Status Board
- Part 19 - Battle City in Unity Part 19 : Bonus Crates - Generation
- Part 20 - Battle City in Unity Part 20 : Bonus Crates - Tank Extra Live
- Part 21 - Battle City in Unity Part 21 : Bonus Crates - Tank Invincibility
- Part 22 - Battle City in Unity Part 22 : Bonus Crates - Grenade
- Part 23 - Battle City in Unity Part 23 : Bonus Crates - Stopwatch
- Part 24 - This Article
- Part 25 - Battle City in Unity Part 25 : Bonus Crates - Shovel
This one is probably the hardest of the bonus crates to create as it has multi-tier changes. Let’s look at what we should expect with the upgrades
- Level 2 (second tier): canonball speed increase.
- Level 3 (third tier): can fire 2 canonballs at a time.
- Level 4 (fourth tier): canonballs can destroy steel walls There is also a tank appearance change per upgrade.
Let’s go straight into creating the routine. The task will be handled by the
Now create a public integer variable called level defaulting it to 1, this is for the tank level tracking and create a new public routine called
We can now code for the changes due to the level up. Since all the changes are on the projectile itself, the best place to write the code will be at the
Upgrade projectile speed
Create a new public routine called
That’s all we need.
2 shots per time
This is probably the most tricky of the 3. Because we are only using a single canonball for all the shots, we will need to create a second canonball. Create a new routine called
We can now update the Fire routine in WeaponController to take in the additional projectile if it is present to have a second shot.
We also need to update the OnDestroy routine to take in the fact that the 2nd canonball needs to be destroyed if the tank is destroyed.
Canonball with destroy steel wall ability
This is probably the easiest of the lot as we have done the preparation work in advance. Create a public routine called
Consolidating everything
Now we can map back all the changes to the UpgradeTank routine in Player script.
Create the bonus crate
Now we will create the bonus crate. Start by dragging and dropping the Sprite you have for Level up bonus crate into the hierarchy which Unity will help to create the Game Object for you. Call the Game Object
Now we will create the code for the LevelUp crate. Add a new script called
Now we are ready to try out! I updated the map with Steel Walls to test all the upgrades.
Level up tank to next stage
One of the important features for the Level Up crate is that the level upgrade gets carried over to next stage. For the information to get carried over to the next stage we will need something that does not get destroyed when moving to next scene, so we will need
Then we need to pass the information of the Tank Level from the stage to MasterTracker before it completes, the place to do this will be the
Then we can add the code of upgraded tank. This will be done at the
Now we go to the WeaponController to add in the code for the powerups. Same as the Player script, we will be adding in the Start Monobehaviour. Also remember to create the public integer variable
The tank’s level will also be reset if it gets destroyed and respawns. So we need to update the Death routine in Health script so that it will reset the MasterTracker’s playerLevel value to 1.The updated code for Death routine as below.
Now 1 last test to see if the level gets carried over to the next stage. We will put 3 LevelUp crates in the scene and leave only 1 enemy so we can destroy it quickly and see if the level up gets moved over.
All cleared! Let’s move to the last bonus crate- Spade.
This article is Part 24 in a 25-Part Series.
- Introduction - Battle City in Unity Prequel
- Part 1 - Battle City in Unity Part l: Single(ton) Sole Survivor
- Part 2 - Battle City in Unity Part 2: Level Creation using Tilemaps
- Part 3 - Battle City in Unity Part 3: Creation of the Protagonist and Antagonists(Tanks)
- Part 4 - Battle City in Unity Part 4: Tank Movement
- Part 5 - Battle City in Unity Part 5: Player Controller
- Part 6 - Battle City in Unity Part 6: Enemy AI
- Part 7 - Battle City in Unity Part 7: Creating Projectiles
- Part 8 - Battle City in Unity Part 8: Hurting the tanks
- Part 9 - Battle City in Unity Part 9: Firing the shots
- Part 10 - Battle City in Unity Part 10: The Spawn
- Part 11 - Battle City in Unity Part 11 : The Gamemaker - Starting the Stage and Game Over
- Part 12 - Battle City in Unity Part 12 : Level Manager
- Part 13 - Battle City in Unity Part 13 : The Gamemaker - Spawning
- Part 14 - Battle City in Unity Part 14 : The Gamemaker - Stage Cleared or Game Over
- Part 15 - Battle City in Unity Part 15 : Spawning Invincibility
- Part 16 - Battle City in Unity Part 16 : Exploding Tank animation
- Part 17 - Battle City in Unity Part 17 : Score Calculation
- Part 18 - Battle City in Unity Part 18 : Battle Status Board
- Part 19 - Battle City in Unity Part 19 : Bonus Crates - Generation
- Part 20 - Battle City in Unity Part 20 : Bonus Crates - Tank Extra Live
- Part 21 - Battle City in Unity Part 21 : Bonus Crates - Tank Invincibility
- Part 22 - Battle City in Unity Part 22 : Bonus Crates - Grenade
- Part 23 - Battle City in Unity Part 23 : Bonus Crates - Stopwatch
- Part 24 - This Article
- Part 25 - Battle City in Unity Part 25 : Bonus Crates - Shovel