Search Unity

my GameOver panel is not being disable

Discussion in 'Scripting' started by ishan711997, Sep 17, 2020.

  1. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19
    Help Please !!!!! i'm a new unity student...

    hey i going through a strange problem i have attached a unity rewarded script and when player finish rewarded video the game over panel should be disable but i won't..... even in my editor when i'm in play mode the game over panel is not disabling by manually Capture1.PNG as you can see my GameOver panel is not a child too.
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    This really doesn't belong here...it should be in a GUI subforum I imagine.

    Why should it be? Is there a place in the code? If so, show the code that disables the panel.
     
    ishan711997 likes this.
  3. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19
    Thank u for reply...

    this code run when enter in level
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Timer : MonoBehaviour
    7. {
    8.     public static Timer instance;
    9.     public float timeStart = 0f;
    10.     // public float extraTime;
    11.     public Text textBox;
    12.     public GameObject GameOverPanel;
    13.  
    14.     void Start() {
    15.         textBox.text = timeStart.ToString();  
    16.         // GameOverPanel.SetActive(false);
    17.     }
    18.  
    19.     public void Update() {
    20.         timeStart -= Time.deltaTime;
    21.         textBox.text = timeStart.ToString("0"); // or can use Mathf.Round(timeStart).ToString()
    22.  
    23.         // this code will set 0 when time go to -ve
    24.         if(timeStart <= 0){
    25.             timeStart = 0;
    26.  
    27.             GameOver();
    28.         }
    29.     }
    30.  
    31.     void GameOver(){
    32.         Time.timeScale = 0;
    33.  
    34.         GameOverPanel.SetActive(true);
    35.     }
    36. }
    below script when i click to rewarded ad btn
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using UnityEngine.UI;
    4. public class Ureward : MonoBehaviour, IUnityAdsListener {
    5.  
    6.     string gameId = "1234567";
    7.     string myPlacementId = "rewardedVideo";
    8.     bool testMode = true;
    9.     public GameObject ClickToCollectBtn;
    10.     public GameObject GameOverPanel;
    11.  
    12.     void Start () {
    13.  
    14.         Advertisement.AddListener (this);
    15.         Advertisement.Initialize (gameId, testMode);
    16.     }
    17.  
    18.     public void ShowRewardedVideo() {
    19.         // Check if UnityAds ready before calling Show method:
    20.         if (Advertisement.IsReady(myPlacementId)) {
    21.             Advertisement.Show(myPlacementId);
    22.         }
    23.         else {
    24.             Debug.Log("Rewarded video is not ready at the moment! Please try again later!");
    25.         }
    26.     }
    27.  
    28.     // Implement IUnityAdsListener interface methods:
    29.     public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
    30.         // Define conditional logic for each ad completion status:
    31.         if (showResult == ShowResult.Finished) {
    32.             Debug.Log("got ");
    33.             Time.timeScale = 1;
    34.             GameOverPanel.SetActive(false);
    35.             ClickToCollectBtn.SetActive(true);
    36.         } else if (showResult == ShowResult.Skipped) {
    37.             // Do not reward the user for skipping the ad.
    38.         } else if (showResult == ShowResult.Failed) {
    39.             Debug.LogWarning ("The ad did not finish due to an error.");
    40.         }
    41.     }
    42. }
    and last code when ad will be finish
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class BonusTime : MonoBehaviour
    7. {
    8.  
    9. public float extraTime = 10f;
    10. public Text textBox;
    11. public GameObject GameOverPanel;
    12.  
    13. [SerializeField] private BonusTime timer;
    14.  
    15.     void Update()
    16.     {
    17.         Time.timeScale = 1;
    18.         Debug.Log("Update called");
    19.         extraTime -= Time.deltaTime;
    20.         textBox.text = extraTime.ToString("0");
    21.         if (extraTime <= 0)
    22.         {
    23.             extraTime = 0;
    24.             Time.timeScale = 0;
    25.             GameOverPanel.SetActive(true);
    26.         }
    27.     }
    28. }
    29.  
     
  4. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Are you getting any errors? The log output "got" prints in your Unity console?
     
  5. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19
    No... No error ....
     
  6. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Are you getting the "got" output in your console? If not, then that piece of code isn't firing and you need to resolve that.
     
    ishan711997 likes this.
  7. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19
    Yes! When i close the ad i am able see "got" print in my console and also my ClickToCollectBtn does active..... but my gameover is continuously showing...
     
  8. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    You're showing the panel every frame in your Timer class. You are disabling it properly, it's just that you're re-enabling it right away.
     
  9. ishan711997

    ishan711997

    Joined:
    Apr 11, 2020
    Posts:
    19
    hey thank u.. thank u so much, i'm so happy now now my problem has solved i destory my script when ad is finished....