Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mata1 · Apr 19, 2020 at 10:25 AM · timetimertime.deltatimecountdowntimers

Time does not start counting down when need to

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);
             }
         }
     //}
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by logicandchaos · Apr 19, 2020 at 04:39 PM

You should move everything in Update in StartGame, then use this for update

 public void Update()
 {
      if (Input.GetMouseButtonDown(0))
      {
          StartGame();
      }
 }

to start with, let me know how things go.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mata1 · Apr 21, 2020 at 12:00 PM 0
Share

I did, it starts on click but i have another problem now, my timer (30sec) does not start counting down, do you maybe know?

avatar image Mata1 · Apr 21, 2020 at 12:05 PM 0
Share

Also my animation stopped working

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CountDown Timer Help (Seconds problem) 2 Answers

Timer reset 1 Answer

countdown timer acivation 1 Answer

Coroutine Countdown Timer being extremely slow 1 Answer

Want to load scene after taking off in plane. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges