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

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

- Download a new game character with animations from the mixamo website (link: https://www.mixamo.com/).
- Download Idle, Walk, and Run Animation Clips.

- Import the character In Unity.

- Right-click on the character file.
- Extract Material and Texture file from the Character Model.

- Drag the character object from the Project Window to the Scene Window.

- Rename the character to “Joe”.

- 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.

- So you will get a character avatar as below.
- An avatar is very useful in applying animation to the character model.


- 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.

- Assign the animator controller to the Animator Component.

- 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.

Idle to Walking Transition Walking to Idle Transition PowerUp to Idle Transition
- Drag the character from the Hierarchy Window to Project Window so it will create a Prefab of the current character object.

PowerUp Object setup
Now you have to add some PowerUps in the Game.
- Download free capsule objects from this website.
- Import the capsule object in the current project.

- Create a material for Capsule Object.

- Create an Empty GameObject in the Hierarchy window and rename it to “PowerUp1”.
- Add a particle system as a child of “PowerUp1”.

- Change the partical system settings as below.
- Here, in Render Mode -> select Mesh
- Render Mesh -> pill_C_001_geo

- 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

- 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class PowerUpScript : MonoBehaviour { //this variable with store PowerUp number public int powerNumber; void OnTriggerEnter(Collider other) { //if any object with Player tag collide with this object when if (other.CompareTag("Player")) { PlayerMovementController.instance.PowerUpActionCalled(powerNumber); Destroy(gameObject); } } } |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UI; public class PlayerMovementController : MonoBehaviour { public static PlayerMovementController instance; //Animation Objects public Animator playerAnimator; //character object public GameObject playerModel; //bool variables public bool isPowerUpAnimation; public bool isPower1Up; public bool isPower2Up; //float variables public float moveSpeed; public float power1Timer; public float power2Timer; public float currentPowerId; //UI Objhects public GameObject Power1Box; public GameObject Power2Box; public Image power1_bar; public Image power2_bar; private void Start() { instance = this; Power1Box.SetActive(false); Power2Box.SetActive(false); } // Update is called once per frame void FixedUpdate() { //If PowerUp Animation is running then the player must stop moving if (!isPowerUpAnimation) { //get Player movement and direction using Input system. Vector3 moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Player will move according to time and speed playerModel.transform.position += Time.deltaTime * moveSpeed * moveDir; //Player will look towards the direction that we want to allow playerModel.transform.rotation = Quaternion.LookRotation(moveDir); if (moveDir.x != 0 || moveDir.z != 0) { playerAnimator.SetBool("isWalk", true); } else { playerAnimator.SetBool("isWalk", false); } } //If PowerUp-1 is On then PowerUP-1's Timer bar will start descreasing if (isPower1Up) { power1_bar.fillAmount -= Time.deltaTime / power1Timer; } //If PowerUp-2 is On then PowerUP-2's Timer bar will start descreasing if (isPower2Up) { power2_bar.fillAmount -= Time.deltaTime / power2Timer; } //When Power1up is Over - PowerUp-1's Effect will stop if (power1_bar.fillAmount == 0) { Debug.Log("Scale Down"); isPower1Up = false; Power1Box.SetActive(false); power1_bar.fillAmount = 1; //Effect gameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f); if(!isPower2Up) { playerAnimator.speed = 1; moveSpeed = 2; } } //When Power2up is Over - PowerUp-2's Effect will stop if (power2_bar.fillAmount==0) { Debug.Log("Speed Down"); isPower2Up = false; Power2Box.SetActive(false); power2_bar.fillAmount = 1; //Effects playerAnimator.speed = 1; moveSpeed = 2; } } //When the Player collides with the PowerUp Capsule this method will be called public void PowerUpActionCalled(int powerId) { currentPowerId = powerId; StartCoroutine(WaitForPowerUpAnimation()); } //for Power up animation IEnumerator WaitForPowerUpAnimation() { //PowerUp animation start isPowerUpAnimation = true; playerAnimator.Play("PowerUp"); playerAnimator.SetBool("isWalking", false); yield return new WaitForSeconds(2); //PowerUp animation over //playerAnimator.SetBool("isWalking", true); isPowerUpAnimation = false; //if powerUp-1 is active then the players scale increases if (currentPowerId == 1) { isPower1Up = true; Power1Box.SetActive(true); power1_bar.fillAmount = 1; Debug.Log("Scale up"); gameObject.transform.localScale = new Vector3(3, 3, 3); moveSpeed = 4; } //if powerUp-2 is active then the players speed increases else if (currentPowerId == 2) { isPower2Up = true; Power2Box.SetActive(true); power2_bar.fillAmount = 1; Debug.Log("Speed Up"); moveSpeed = 6; playerAnimator.speed = 2; } } } |
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.

camera follow Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollowController : MonoBehaviour { //The Target Object public Transform targetObject; //Default minimum distance between the target and the player public Vector3 cameraOffset; //Smooth factor will use in Slerping public float smoothFactor = 0.5f; // Start is called before the first frame update void Start() { cameraOffset = transform.position - targetObject.transform.position; } // Update is called once per frame void LateUpdate() { //Camera Position Change Vector3 newPosition = targetObject.transform.position + cameraOffset; transform.position = Vector3.Slerp(transform.position, newPosition, smoothFactor); } } |
- Change the Camera Position and rotation as below.
- Assign CameraFollowController Script to Camera.

Final Output
Summary
In This Article, you learned about the Power Up System using it in a simple game.
Leave A Comment