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 Firelights · Jul 21, 2016 at 04:27 PM · uidestroydestroygameobjectdestroy-clones

UI Object is there but can't destroy it.

I am implementing UnityAds in my game and have some UI I want to show and hide, for that I am Instantiating objects(using the InstantiateUI function) and then Destroying them.

All the UI I use is in a simple class:

[System.Serializable] public class ads{

     public Text AdTxt;
     public Button WatchAd;
     public Button Skip;
     public Text tyTxt;
             [HideInInspector]
     public GameObject _tyAd;
     [HideInInspector]
     public GameObject _AdTxt;
     [HideInInspector]
     public GameObject _SkipAd;
     [HideInInspector]
     public GameObject _WatchAd;
         
 }

Note: the underscored GO are defined null and will later get assigned as the clones of the not underscored objects.

tyAd is called after the Ad is Shown,it deletes some UI I don't want anymore and creates a Text thanking the player for watching an ad.

public void tyAd(){

 Destroy(Ads._AdTxt.gameObject);
 Destroy(Ads._WatchAd.gameObject);
 Destroy(Ads._SkipAd.gameObject);
 Ads._tyAd = InstantiateUI(Ads.tyTxt.gameObject);
     

} Note: The Ads.tyTxt is a GO with a Text and a Button Component.

AdResume gets called after the player Clicks the Button:

public void AdResume(){

 Time.timeScale=1;
 print (Ads._tyAd.name);
 Destroy(Ads._tyAd.gameObject);

}

Here is the problem: The Ads._tyAd.gameobject doesn't get destroyed and stays in the scene.

If you think this may have something to do with it, here is the InstantiateUI function:

GameObject InstantiateUI(GameObject UI){

     GameObject clone=Instantiate(UI)as GameObject;
     clone.transform.SetParent(GameObject.Find("Canvas").transform,false);
     return clone;
 }
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Destroy() not working on prefab instance 2 Answers

Destroy Objects after a set time 2 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Check not colliding when object has been destroyed,Check if object no longer colliding if it's been deleted 0 Answers

Can you destroy an object using GetInstanceID? 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