Hey!
I’m trying to do something that seems pretty simple in my head, but once I try and do it, I’m Not 100% sure how to. Been trying for while now but hope someone can help!
Overview:
I have 2 Buttons:
Button A = Stops the round and Time
Button B = Starts the next round with the NEW Time
HELP with this:
The 1st game round is 10 seconds (normalTime) and once I click “Button A” my time pauses(works).
Then I want to click “Button B”, it will start the next round, HOWEVER it will be the time that I needed in the last round.
Meaning:
- Round 1: 10 Seconds standard (I finished it in 9 seconds, meaning round 2 is 9 seconds)
- Round 2: 9 seconds due to previous round ( finished it in 3 seconds though, round 3 is 3 seconds
- Round 3: 3 seconds etc.
I am not sure how to set variables to one another, when I try normalTime = elapsedTime; after the button was clicked it just sets them both to 0. So, how would I do this best?
Thank you!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MyTimer : MonoBehaviour
{
// currently on public to see information
public float normalTime = 10.0f; // My Timer
public float startTime = 10.0f; // Variable to have the round length
public float elapsedTime;
// Shows the Timer
public Text text;
// Shows that Timer is running, if False then normalTime is stopped.
public bool timerOn = true;
// Button was clicked
public bool roundEnd = false;
void Start ()
{
roundEnd = false;
}
void Update ()
{
if (timerOn)
{
normalTime -= Time.deltaTime;
}
// text.text = "Time Left: " + Mathf.Round (timeLeft); // Round Number to full Numbers
text.text = "Time Left: " + Mathf.Abs (normalTime); // Shows Exact Time (with multiple decimals)
if (normalTime < 0)
{
SceneManager.LoadScene ("GameOver");
}
}
public void ButtonWasClicked ()
{
// startTime -= normalTime = elapsedTime;
//normalTime = elapsedTime;
roundEnd = true;
print (" ==== BUTTON PRESSED ==== " + "Time Left: " + normalTime);
timerOn = false;
}
public void NextRound ()
{
print ("ACTION");
}