How to make a power meter

So I want to make a game where you have a vertical power meter that, is numbered from 1-100. turns from blue to red. And goes up and quickly goes back down. When you tap on the screen the bar has to stop at a certain point in order to progress the game and as the game progresses the power meter goes back down more quickly. But the problem is I don’t know how to make this I have searched up and down all over the internet and I can’t find a solution.

Okay, so from what I gather you want a power meter that moves up and down, when the player clicks you want the meter to stop and depending on where it is the player either wins or loses. If they win the downward speed increases.

I’ve done this using sprites, it could also be done with UI elements.

In the inspector you will need to set;
The upwards movement speed.
The downwards movement speed.
The max height you want the line to reach.
The min height you want the line to reach.
The max height of the ‘win area’
The min height of the ‘win area’

Here’s the script, I’ve annotated it as best as I can so you can follow along and modify it as you need:

using UnityEngine;
using System.Collections;

public class LineMove : MonoBehaviour {
	bool upOrDown = true; //whether we are moving up or down
	bool stopped = false;	//whether we have stopped or not
	public float upSpeed;	//our upwards movement speed
	public float downSpeed;	//our downwards movement speed
	public float maxHeight;	//the max height at which we will change direction
	public float minHeight;	//the min height at which we will change direction
	public float minWinHeight;	//the minimum height we must be at to win
	public float maxWinHeight;	//the maximum height we must be at to win

	void Update () {
		if (Input.GetKeyDown (KeyCode.Mouse0)) {	//if the mouse is clicked
			stopped = true;	//then stop
			Stopped ();
		if(!stopped){ //if we haven't stopped
			MoveUpDown (); //move line

	void MoveUpDown()
		if (upOrDown) {	//if we are moving up
			transform.Translate (Vector3.up * upSpeed);	//move up
			if (transform.position.y > maxHeight) {	//if we are at the max height
				upOrDown = false;	//switch to moving down
		} else {	//if we are moving down
			transform.Translate (Vector3.up * -downSpeed);	//move down
			if (transform.position.y < minHeight) {	//if we are at the min height
				upOrDown = true; //switch to moving up

	void Stopped()	//when we have stopped
		if (transform.position.y > minWinHeight && transform.position.y < maxWinHeight) {
			Debug.Log ("YOU WIN!!!");	//if line is between win min and max height we win or lose
		} else {
			Debug.Log ("YOU LOSE");

If the line stops between minWinHeight and maxWinHeight then it will tell the player that they have won in which case you want to increase the downwards speed. In the part that that has Debug.Log(“YOU WIN”) add downSpeed += 0.1f or however much you want to increase it by.

        Debug.Log("YOU WIN");
        downSpeed +=0.1f;   //increase downwards speed.

If you want to reset the line use:

    transform.position = new Vector3(transform.position.x,minHeight,transform.position.z);             //resets position
     stopped = false;   //start moving again

In its current state it wont do anything after the line has stopped, it’s up to you to implement that :wink:
Heres what mine looks like:

Yellow area represents where the player wins. Obviously you could do something a lot more fancy and can add in numbers seperately. This script ended up a bit more complex than it needed to be but I just wanted to use basic stuff without Coroutines, Lerping and such, so that you could follow along and more easily modify it. Anyway I hope this helps, gives you a framework to work with at the very least. All the best :slight_smile: