Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jan 26 at 06:13 PM by burchland2 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by burchland2 · Jan 23 at 03:39 AM · timer-scriptgame over

Game Over Canvas not showing

I think I messed something up.

I'm pulling my hair out working on this. When the allotted time counts down and reaches zero, the TimeOver canvas does not show up. The same thing is happening to the GameOver canvas each time the player is out of lives. Here is the code for both.

CountdownTimer.cs:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 using System;
 
 public class CountdownTimer : MonoBehaviour
 {
     public static float startingTime = 45f;
 
     public static float countingTime;
 
     public Text theText;
 
     public GameObject outOfTime;
 
     public HealthManager theHealth;
 
     public CameraController cam;
 
     public UnitManager um;
 
     private AudioSource source1;
 
     public GameObject gameOver;
 
     public AudioClip bat;
 
     public AudioClip bell;
 
     public AudioClip net;
 
     public bool isPaused;
 
     public bool timerActive = true;
 
     public PlayerController ball;
 
     public GameStatus gs;
 
     public int moveOnDelay = 3;
 
     void Start()
     {
         outOfTime.gameObject.SetActive(false);
         countingTime = startingTime;
         theHealth = FindObjectOfType<HealthManager>();
         source1 = GetComponent<AudioSource>();
         um = FindObjectOfType<UnitManager>();
         ball = FindObjectOfType<PlayerController>();
         gs = FindObjectOfType<GameStatus>();
     }
 
     void Update()
     {
         if (isPaused)
         {
             return;
         }
 
         if (timerActive)
         {
             countingTime -= Time.deltaTime;
             theText.text = "Time: " + Mathf.Round(countingTime).ToString("f0");
 
             if (countingTime <= 10f)
             {
                 TimeRunningOut();
             }
 
             if (countingTime <= 0f)
             {
                 TimeUp();
             }
         }
     }
 
     public void ResetTime()
     {
         countingTime = startingTime;
         theText.color = Color.blue;
     }
 
     public void TimeRunningOut()
     {
         theText.color = Color.red;
     }
 
     public void UpdateScore()
     {
         if (countingTime <= 10f)
         {
             gs.AddScore(500);
         }
         else
         {
             int timeScore = (int)countingTime * 2;
             gs.AddScore(timeScore);
         }
         ResetTime();
         timerActive = false;
     }
 
     public void TimeUp()
     {
         if (countingTime <= 0f)
         {
             countingTime = 0f;
             theHealth.DestroyPlayer();
             if (GameStatus.lives > 1 && !theHealth.isDead)
             {
                 StartCoroutine("TimeOverCo");
             }
 
             if (GameStatus.lives == 1 && !theHealth.isDead)
             {
                 gameOver.gameObject.SetActive(true);
             }
         }
     }
 
     public IEnumerator TimeOverCo()
     {
         outOfTime.gameObject.SetActive(true);
         yield return new WaitForSeconds(3);
         outOfTime.gameObject.SetActive(false);
         ResetTime();
     }
 }

GameOver.cs:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class GameOver : MonoBehaviour
 {
     public float waitAfterGameOver = 10f;
     public Text txt;
     public UnitManager um;
     private CountdownTimer ct;
     public GameObject gameOver;
     public PlayerController ball;
 
     // Start is called before the first frame update
     void Start()
     {
         um = FindObjectOfType<UnitManager>();
         ct = FindObjectOfType<CountdownTimer>();
         gameOver.gameObject.SetActive(false);
     }
 
     public void GameOverScreen()
     {
         gameOver.gameObject.SetActive(true);
         waitAfterGameOver -= Time.deltaTime;
 
         if (waitAfterGameOver <= 0)
         {
             um.StartOver();
         }
         txt.text = "Continue? " + Mathf.Round(waitAfterGameOver);
         txt.color = Color.green;
     }
 
     public void Quit()
     {
         Application.Quit();
     }
 }
 

What should I do to make both panels work?

alt text

alt text

screenshot-2022-01-22-223443.png (7.0 kB)
screenshot-2022-01-22-223548.png (10.0 kB)
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

  • Sort: 
avatar image
0

Answer by privatecontractor · Jan 23 at 05:56 AM

Hi @burchland2 ,

Man inside this part try to add:

              theHealth.DestroyPlayer();
              if (GameStatus.lives > 1 && !theHealth.isDead)
              {
                  **Debug.Log("Made condition to call: TimeOverCo");**
                  StartCoroutine("TimeOverCo");
              }
  
              if (GameStatus.lives == 1 && !theHealth.isDead)
              {
                  **Debug.Log("Made condition to call: GameOver.StaActive(true);**
                  gameOver.gameObject.SetActive(true);
              }



So you will see is this problem with conditions which not ocurre or with voids/coorutines called...

Also you write that time is running, so if conditions are not checked what is doing void: theHealth.DestroyPlayer(); probably seeting some bool like isDead to true, check this out... maybe you changing private bool and not updating public etc... or maybe you check is:

 !theHealth.isDead

(beacuse you checking for false value...) so he isAlive ?

 theHealth.isDead

So lets startr with Debug.Log() and look why...

Hope will do, if you will still strugling provide feedback, and will look some more.

Comment
Add comment · Show 1 · 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 burchland2 · Jan 23 at 10:08 PM 0
Share

Thank you very much for your help! I think I'm finished with the base portion of the game now. Again, I appreciate your assistance.

Sincerely, burchland2

Follow this Question

Answers Answers and Comments

131 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

Related Questions

How do I make my timer continue to count? (C# Script) 2 Answers

How to make timer for music in my android app(20,30 and 60 min)? in #c 0 Answers

Bring down the value with time 1 Answer

after going to main menu my game wont play? 2 Answers

Timer ends game 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