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 /
avatar image
0
Question by Styxer · Jan 05, 2014 at 05:41 PM · c#guidestroy

destroty gui object

hi guys i want to destroy GUI object heres what i have done

 using UnityEngine;
 using System.Collections;
 
 public class PowerUpScript : MonoBehaviour {
 
     int random = 0;
     float timer = 3;
 
     // Use this for initialization
     void Start () {
 
 
     }
     void Update()
     {
         if (timer >= 1 && random == 1) {
             guiText.text = timer.ToString ("something");
         } else if (timer >= 1 && random == 0) { // timer is <= 0
             guiText.text = timer.ToString ("otherThing");
         } //else            
             //Destroy (??);    
     }
 
     
     
     
     void OnTriggerEnter (Collider other) 
     {
         random = 0;
         PadleScript paddleScript = GameObject.Find ("paddle").GetComponent<PadleScript>();
         if(random==0)
             paddleScript.AddPoints (50);
         if (random == 1)        
         {
             paddleScript.spawnball ();
         }
 
         Destroy (gameObject);
     }
 }

p.s im also getting a weird warning : "MissingComponentException: There is no 'GUIText' attached to the "powerUp" game object, but a script is trying to access it. You probably need to add a GUIText to the game object "powerUp". Or your script needs to check if the component is attached before using it. PowerUpScript.Update () (at Assets/Scripts/PowerUpScript.cs:19)"

thanks

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

Answer by RyanPaterson · Jan 05, 2014 at 06:13 PM

From what I know you can't destroy GUI. I think I attempted this not too long ago. You will probably have to use a bool to say when to display it and when to not.

So for example you could have like,

bool isShowing = false; - where you wanted to have Destroy() and: bool isShowing = true; when you initialise your GUI


EDIT: In answer to your comment

I didn't want to use your code because honestly i'm not familiar with guitext myself, so I took your update function and used it as an example to show you how the bool idea works.

*In this example GUI.Label just creates a box with text.

Here i've set the myVisibleBool to be true, although when you do it your calculations will determine whats true and whats not (which is why from what i've wrote you won't ever see the text "Other thing" because I didn't mess about with numbers for the example.

So what this does is -- When the requirements of the 'if statement' are met, it will draw some text. (same as yours; however) The bool will show true/false, in this case is like 'hide/unhide' . As I don't think you can Destroy GUI.

The update function is just something I added in there as a method of switching off and on the boolean. the myVisibleBool = !myVisibleBool just flips the value each time it's pressed.

Let me know if you're unsure, what you're unsure about. I'd recommend looking at booleans and such on youtube, theres a few basic programming ones I looked at myself quite recently, they're a big help, and very common.

         bool myVisibleBool = true;
         int timer = 2; 
         int random = 1;
         
         void OnGUI(){
                 if (timer >= 1 && random == 1 && myVisibleBool == true){
                 GUI.Label(new Rect(10, 10, 100, 20), "Something");
             }
     
             if(timer >= 1 && random == 0 && myVisibleBool == false) { // timer is <= 0
                 GUI.Label(new Rect(10, 10, 100, 20), "Other Thing");
             } 
         }
     
         void Update(){
     
             if(Input.GetKeyDown (KeyCode.Space)){
                     myVisibleBool = !myVisibleBool;
                 }
             }
     
Comment
Add comment · Show 3 · 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 Styxer · Jan 08, 2014 at 01:00 PM 0
Share

can you show me what you did i still cant find solution to my problem

avatar image RyanPaterson · Jan 08, 2014 at 02:35 PM 0
Share

I revised my answer above with the answer to your comment. Let me know if you don't understand.

avatar image Styxer · Jan 11, 2014 at 06:45 PM 0
Share

thanks mate (i know what bool means btw) i just dont understand the "if" condition on update function if i understand correctly it means that only if i press the spacebar key it changed to false

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

19 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

Related Questions

How do I destroy a Instantiated UI image that is pushed on the Canvas? 2 Answers

[Fixed] Unity UI Text Code Reference magically dissapears 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Create Multiple Foldouts. 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