Power..Power..Power

What is a Power up?

Power-ups are interesting and useful components to make a game more interesting.

In this Article you will learn how to:

  • create PowerUp system
  • create a simple game demo with PowerUps

NOTE : You must have knowledge of basic Unity concepts and c# language. If you are fresher in Game Development then study this tutorial _____link____

PowerUp Demo in Unity

Create a new Unity Project

Unity Hub

Import 3D Environment & Character

Click here -> https://assetstore.unity.com/packages/3d/environments/urban/toon-gas-station-155369

3D Asset
Character of Mixamo Website
  • Download Idle, Walk, and Run Animation Clips.
Character with animation downloading
  • Import the character In Unity.
All animation clips
  • Right-click on the character file.
  • Extract Material and Texture file from the Character Model.
Extract material and texture from Character Object
  • Drag the character object from the Project Window to the Scene Window.
Drag the object from the project window to the hierarchy window
  • Rename the character to “Joe”.
Character Rig Menu
  • In the project window, right-click on the player and go to the settings.
  • Select “Create From This Model” option in avatar Definition.
  • Select the Root node from the list.
Create an avatar of the character object
  • So you will get a character avatar as below.
  • An avatar is very useful in applying animation to the character model.
Avatar in Character Model
Add Rigidbody and Capsule Collider
  • Add an Animator Component to the Character Object.
  • There is no Animator controller available in Animator. So you have to build a new one.
  • For that, go to the project window, right-click & create Animator Controller.
Animation Controller
  • Assign the animator controller to the Animator Component.
Assign the animator controller and Avatar
  • Go to Window > Animation >Animator > Open the Animator Window.
  • Create a parameter in Animator Window -> isWalking Bool.
  • Add three animation clips in this Animator controller.
    • Idle
    • Walking
    • PowerUp
  • Assign transition arrow to each animation clips.
Animator Window
  • Drag the character from the Hierarchy Window to Project Window so it will create a Prefab of the current character object.
Character Prefab

PowerUp Object setup

Now you have to add some PowerUps in the Game.

  • Import the capsule object in the current project.
Capsule model and texture files
  • Create a material for Capsule Object.
create a new material for Capsule
  • Create an Empty GameObject in the Hierarchy window and rename it to “PowerUp1”.
  • Add a particle system as a child of “PowerUp1”.
Steps of Particle system
  • Change the partical system settings as below.
  • Here, in Render Mode -> select Mesh
  • Render Mesh -> pill_C_001_geo
Capsule Mesh
  • Duplicate the PowerUp1 Object and rename duplicated object as “PowerUp2”.
  • In PowerUp2, all are same, just replace Render Mesh – pii_C_002_geo
  • so you will get 2 powerUp Capsules
Power Up Capsules
  • In-Game, when the player touches the capsule, the player will get power and becomes bigger.
  • So you have to add a box collider in both PowerUp Objects.
  • Turn the isTrigger property on the box collider component of PowerUps.
  • Create a new c# script with the name “PowerUpScript.”
  • Assign this script to both PowerUps Objects.

PowerUpScript

Here,

  • When character joe (tag player) will collide with this power-up object at that time this script will execute.
  • It will be called the method of another script and pass the power number in it.

PlayerMovementController Script

  • Create a new c# script for Player Movement and Power Up Actions.
  • Rename this script to the “PlayerMovementController.”
  • Assign the PlayerMovementController script to our Joe Character.

Here,

  • When the Player touches the Power Up Capsule Object, at that time the PowerUpActionCalled() method will be called with power id.
  • Then the power number will be stored in CurrentPowerId Variable and one coroutine method call for PowerUp Animation.
  • It will set isPowerUpAnimation boolean variable as true.
  • It will execute a process for 2 seconds to complete PowerUp Animation first.
  • After that, the isPowerUpAnimation boolean variable is set to false because the PowerUpAnimation is over.
  • Now if currentPowerId =1 then isPower1Up boolean will be true so,
    • PowerUP-1 Bar is active
    • isPower1Up bool is true
    • PowerUP-1 Bar value set to full
    • Character scale set to 3
    • Increase Movespeed=4
  • If currentPowerId =2 then
    • PowerUP-2 Bar active
    • isPower2Up bool is true
    • PowerUP-2 Bar value set full
    • Increase Movespeed=8
  • so isPower1Up bool is true, then Power1Up’s Timer starts decreasing from Timer value to 0. Once it reached 0, Power1Up’s Effect will disappear.
  • same condition for Power2Up
  • If the value of power1_bar.fillAmount is zero then
    • isPower1Up is false
    • Deactivate Power1 bar
    • Character scale set to normal
    • power1_bar.fillAmount=1 (otherwise loop iterating continue)

Adding the UI Components

  • Now you have to add two power bars to show power effect timing on the screen.
  • Click on the “+” button and add the UI Canvas object in the Hierarchy window.
  • Add an image on the top left side of the screen in Canvas and rename it to “Power1Box.
  • Add another image object as a child of Power1Box and rename it to Power1_Bar.
  • Duplicate “Power1Box” and create Power2Box.
PowerUp1 & PowerUp2 timer bar

camera follow Script

  • Change the Camera Position and rotation as below.
  • Assign CameraFollowController Script to Camera.
Camera Settings

Final Output

Output

Summary

In This Article, you learned about the Power Up System using it in a simple game.