Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 charleneconcha · Oct 12, 2020 at 07:35 AM · timerreload

MY TIMER RESTART WHEN RELOADING THE SCENE.

WHEN RELOAD MY SCENE BECAUSE OF WRONG INPUT I WANT MY TIMER IS STILL RUNNING IT WILL STOP IF THEY PUT THE CORRECT POSITION

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 using System.Security.Cryptography;
 
 public class vRingLevel1GameControl1 : MonoBehaviour
 {
     public static vRingLevel1GameControl1 instance;
     public GameObject vRingL1Close, vRingLevel1Close2, vRingLevel1Slide, vRingPole, vRingBlue1, vRingRed1, vRingYellow1;
     public Text timeCounter, countdownText, congratsText;
     public bool gamePlaying { get; private set; }
     public int countdownTime;
     private float startTime, elapsedTime;
     TimeSpan timePlaying;
 
     public static int slotsOccupied;
     [SerializeField]
     private Transform[] rings;
     [SerializeField]
     private GameObject wrongSign;
 
     private void Awake()
     {
         instance = this;
     }
 
     private void Start()
     {
         timeCounter.gameObject.SetActive(false);
         congratsText.gameObject.SetActive(false);
         vRingL1Close.SetActive(false);
         vRingLevel1Close2.SetActive(false);
         vRingLevel1Slide.SetActive(false);
         vRingPole.SetActive(false);
         vRingBlue1.SetActive(false);
         vRingRed1.SetActive(false);
         vRingYellow1.SetActive(false);
         timeCounter.text = "00:00";
         gamePlaying = false;
         StartCoroutine(CountdownToStart());
 
         vRingLevel1Drag.PuzzleDone += CheckResults;
         slotsOccupied = 0;
         wrongSign.SetActive(false);
     }
 
     private void BeginGame()
     {
 
         gamePlaying = true;
         startTime = Time.time;
     }
 
     private void Update()
     {
 
         if (vRingLevel1Close.locked)
         {
             vRingLevel1Close.locked = false;
             SceneManager.LoadScene("vRingLevelUI");
         }
 
         if (gamePlaying)
         {
             elapsedTime = Time.time - startTime;
             timePlaying = TimeSpan.FromSeconds(elapsedTime);
             string timePlayingStr = timePlaying.ToString("mm':'ss");
             timeCounter.text = timePlayingStr;
         }
     }
 
     public void CheckResults()
     {
         if (rings[0].position.y == -0.04f &&
             rings[1].position.y == -1.81f &&
             rings[2].position.y == -3.62f)
         {
             gamePlaying = false;
             congratsText.gameObject.SetActive(true);
         }
         else
         {
             wrongSign.SetActive(true);
             Invoke("ReloadGame", 1f);
         }
     }
 
     private void ReloadGame()
     {
         vRingLevel1Drag.PuzzleDone -= CheckResults;
         SceneManager.LoadScene("vRingLevel1");
     }
 
     IEnumerator CountdownToStart()
     {
         while (countdownTime > 0)
         {
             countdownText.text = countdownTime.ToString();
             yield return new WaitForSeconds(1f);
             countdownTime--;
         }
         BeginGame();
         countdownText.text = "GO!";
         yield return new WaitForSeconds(1f);
         timeCounter.gameObject.SetActive(true);
         countdownText.gameObject.SetActive(false);
         congratsText.gameObject.SetActive(false);
         vRingL1Close.SetActive(true);
         vRingBlue1.SetActive(true);
         vRingRed1.SetActive(true);
         vRingYellow1.SetActive(true);
         vRingPole.SetActive(true);
     }
 }

Comment
Add comment · Show 2
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 Fornoreason1000 · Oct 10, 2020 at 03:05 AM 0
Share

Have you tried all of these solutions? https://answers.unity.com/questions/1219988/countdown-to-persist-through-scenes.html

avatar image charleneconcha Fornoreason1000 · Oct 11, 2020 at 06:51 PM 0
Share

i will try it hope this code will help me. i will update you. im a beginner in making a 2d unity game. thank you for your response

0 Replies

· Add your reply
  • Sort: 

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

139 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reload level after timer hits 0 1 Answer

Time.deltaTime stops counting up, after the Player is destroyed 1 Answer

Reload Courutine Taking To Much Ammo 1 Answer

Time.time stops working after reloading a level 4 Answers

How do I Reset Scene 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