Using Power-Ups

In this tutorial, students will create power-ups for their game

Jump Boost



Let's add some power-ups to our game that will change the way the character moves.

First, create a script called PowerJump. Then, copy the below code into the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PowerJump : MonoBehaviour
{
    //Creates the multiplier for the power-up
    public float powerBoost = 2f;

    private void OnTriggerEnter(Collider other)
    {
        //Multiplies the Player's jump height by 2
        other.GetComponent<FirstPersonController>().jumpHeight *= powerBoost;

        //Destroys the object
        Destroy(gameObject);
    }
}
            


Like the previous collectibles and hazards we need to create a 3D Object for the power-up. Make the collider into a trigger, then put the new script on the object in the Inspector. Adjust the power of the boost to your liking. It will multiply the player's jump ability by that amount.



Speed Boost



Now to make a power-up that increases the Player's speed.

The code is very similar to the PowerJump script, but instead we are changing speed. Create a script called SpeedBoost, then copy the below code into the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedBoost : MonoBehaviour
{
    //Creates the multiplier for the power-up
    public float powerBoost = 5f;

    private void OnTriggerEnter(Collider other)
    {
        //Multiplies the Player's speed by 5
        other.GetComponent<FirstPersonController>().speed *= powerBoost;

        //Destroys the object
        Destroy(gameObject);
    }
}
            


Just like with the PowerJump script, create a Game Object, check the Is Trigger box in the collider, and add the script you just made, as presented in the video above.


Wrap-up Activity


World Objects Demo

When you have finished adding your power-ups, record a video screen capture of you playing the game that demonstrates inclusion of all required elements. View the rubric for this project below for a complete list of required elements.

The recording created should be long enough to demonstrate your inclusion of required elements without exceeding one minute. If elements are placed far apart in an expansive world, you may edit the video to remove portions that are not necessary.

How did you do? Take a moment to reflect by completing the Evaluation Rubric for the World Objects Demo.

You may Create a Copy of the Evaluation Rubric for your own use.