Hello, im making 2d mobile game and i came to problem. So my game starts on click and timers and every element shows on that click and needs to start when i touch the screen, and here is the problem, my timer of game doesnt start countdown on click it just shows himself, i know this code isnt right i tried to fix it with another method and all kinds of stuff, but no luck. Btw my timer is in update function. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.SceneManagement;
public class TimerIIgra : MonoBehaviour {
//za tajmer 30s
private float timerIgre = 30f;
[SerializeField] private Text textTimeraIgre;
[SerializeField] private Text textFinishedScore;
[SerializeField] private Text tapCounterText;
public int tapCounter = 0;
[SerializeField] public GameObject retryButton;
[SerializeField] public GameObject mainMenuButton;
//public countDownTimer countDownTimerScript;
public bool gameStart = false;
//public bool gameStarted = true;
public Animator animator;
void Start () {
//textTimeraIgre = GetComponent<Text>();
textTimeraIgre.text = "";
tapCounterText.text = "";
textFinishedScore.text = "";
retryButton.SetActive(false);
mainMenuButton.SetActive(false);
animator = GetComponent<Animator>();
//if (Input.GetMouseButtonDown(0))
//{
//gameStart = true;
//}
//StartGame();
}
public void Retry()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void BackToMenu()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
/*public void StartGame()
{
if (Input.GetMouseButtonDown(0))
{
gameStart = false;
}
}*/
void Update()
{
//if (Input.GetMouseButtonDown(0))
//{
//gameStart = true;
if (gameStart == true)
{
textTimeraIgre.text = "30";
timerIgre -= Time.deltaTime;
textTimeraIgre.text = timerIgre.ToString("f0");
if (Input.GetMouseButtonDown(0))
{
animator.SetBool("isPressed", true);
tapCounter++;
tapCounterText.text = tapCounter.ToString();
}
else
{
animator.SetBool("isPressed", false);
}
if (timerIgre <= 0)
{
tapCounterText.text = "";
gameStart = false;
textTimeraIgre.text = timerIgre.ToString("Time's Up!");
textFinishedScore.text = "Score: " + tapCounter.ToString();
//FindObjectOfType<GameManager>().EndGame();
retryButton.SetActive(true);
mainMenuButton.SetActive(true);
}
}
//}
}
}