Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 eni_cay · Dec 12, 2019 at 09:01 PM · uiprefabdisplaypanelgameover

ui panel disappears after showing for few seconds ?(problem)

i have a endless game , balls spawn endlessly and when wrong collision happens it shows a game over panel , the panel shows just fine but it doesnt last , it only shows for like 1 or 2 seconds then disappears

Environment : ball script which is attached to the ball prefab

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using GoogleMobileAds.Api;

public class ball : MonoBehaviour { public static ball instance; public string currentcolor; public SpriteRenderer sr; public int targetscore = 10; public Color colorred; public Color coloryellow; public Color colorblue; public AudioSource collsound; float speed = 7; public GameOver_s gameOver; public float score; public GameManager CurrentScore; //-------------- public GameObject Panel; //----------- public GameObject BallSpawner ; // private bool isDead = false; private float StartTime;

 //----------------
  

 // Start is called before the first frame update
 void Start()
 {
     hidePanel();
     collsound = GetComponent<AudioSource>();
    
     SetRandomColor();
     
 }
 void Update()
 {
     transform.Translate(Vector3.down * speed * Time.deltaTime);
 }
 void OnTriggerEnter2D(Collider2D col)
 {

     if (col.tag == "ball")
     {
         gameObject.GetComponent<AudioSource>().Play();
         
         Debug.Log(currentcolor);
     }
     if (col.tag == "colorchanger")
     {

         SetRandomColor();
         return;
     }

      if (col.tag != currentcolor)
     {
   
         Destroy(GameObject.Find("circle"));
         Destroy(GameObject.Find("circle (1)"));
         Destroy(GameObject.Find("circle (2)"));
         ShowPanel();
        
         return;
         
      }

     GameManager.singleton.AddScore(1);
    
 }

public void OnAdPanelExited () {

     SceneManager.LoadScene("GameOver");
     
 }

 void SetRandomColor()
 {
     int index = Random.Range(0, 3);
     switch (index)
     {

         case 0:
             currentcolor = "yellow";
             sr.color = coloryellow;
             break;
         case 1:
             currentcolor = "red";
             sr.color = colorred;
             break;
         case 2:
             currentcolor = "blue";
             sr.color = colorblue;
             break;
     }

 }
 public void ShowPanel()
 {
     AdPanelManager.instance.DisplayPanel(); 
 }
 public void hidePanel()
 {
     AdPanelManager.instance.HidePanel();
 }

} and here is the one attached to the panel : using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class AdPanelManager : MonoBehaviour {

 public GameObject Panel;
 public static AdPanelManager instance;

 private void Awake()
 {
     //Check if instance already exists
     if (instance == null)


         instance = this;

     else if (instance != this) 

       Destroy(gameObject);
      
     DontDestroyOnLoad(gameObject);
     
 }
 // Start is called before the first frame update
 void Start()
 {
     //Panel = GameObject.Find("ADPanel_Holder");
     HidePanel();
 }
 public void DisplayPanel()
 {
     Panel.SetActive(true);
     //DontDestroyOnLoad(gameObject);
 }
 public void HidePanel()
 {
     Panel.SetActive(false);
 }

}

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
Best Answer

Answer by oTaijjo · Dec 13, 2019 at 08:15 AM

Can't find anything wrong with the code. I suspect it's related to the setup of your scene. You could check the following:

  • Awake(), Start() etc. are NOT called when the scene is loaded, if the respective GameObject is not active. You have a hidePanel() in a Start() method there somewhere, maybe this is a call order issue?

  • If you're using Uniy UI (Canvas, Images'n stuff) check if you show some UI element with a non 0 z coordinate. I recently ran into the issue of the canvas disappearing, when I put a wrong number into ONE UI element's z coordinate.

  • Check if OnTriggerEnter2D() is called more often than expected. Maybe it screws with things.

That's all I could come up with. Good luck!

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 eni_cay · Dec 13, 2019 at 10:52 AM 0
Share

thank you , exactly what i needed , was adding the hide panel function in void start , and removing that function fixed it !

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

220 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 send inputfield text to another script? 0 Answers

Display remaining knives UI ? (knife hit style) 0 Answers

GameObject.setActive(true) not working despite children and parents are active 1 Answer

Game Over Screen appears on launch.,Something with my script makes it so that everytime I run it a gameover happens 1 Answer

EventSystem not recognizing child objects 0 Answers


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