- Home /
Question by
KoreanCookie01 · Dec 12, 2021 at 06:24 PM ·
unity 2d
Score Counter for a clicker game
Hi everyone, I'm new to Unity and need help. I have a clicker game with a progress bar and now need to add score counter to it. I need a point added to score counter every time the progress bar hits maximum and the clicker should turn off. Then after the progress bar empties, the process should start again. After the score counter hits 20 points, I need "Congrats, you win!" displayed and the option to play again. Hope you can suggest solutions! Here's the progress bar code I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ClickScript : MonoBehaviour {
public Image clickMeter;
public float curMeter, maxMeter;
public float incMeter;
public float decMeter;
public float meterReduceTimer;
public float timeBetweenClicks;
void Update () {
ImageChange();
MaxMinValue();
Clicking();
ReduceMeter();
}
public void Clicking()
{
if (Input.GetKeyDown(KeyCode.Space))
{
curMeter += incMeter;
meterReduceTimer = 0;
}
}
void ReduceMeter()
{
meterReduceTimer += 1;
if(meterReduceTimer > timeBetweenClicks)
{
curMeter -= decMeter;
}
}
void ImageChange()
{
clickMeter.fillAmount = curMeter / maxMeter;
}
void MaxMinValue()
{
if(curMeter < 0)
{
curMeter = 0;
}else if(curMeter > maxMeter)
{
curMeter = maxMeter;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
2D Physics and Jump-Through Platforms 2 Answers
Get Width of 2d Game Object 1 Answer
How can I stop my object pool from firing? 0 Answers