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
1
Question by siberman · Oct 24, 2011 at 09:01 AM · guibuttondestroy

GUI destroy instantiated Objects

Hello,

I've been scouring these forums for hours, and made lots of progress, but this is really stumping me.

Basically i have a GUItexture that i want to destroy a bunch of Cubes, spawned by another GUItexture. I'm a programming noob coming from Maya, i'm getting this error;

Assets/Scripts/KillSpawned.js(21,12): BCE0023: No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '(System.Type)' was found.

from this script;

 var spawn : GameObject[];
     spawn = GameObject.FindGameObjectsWithTag("Spawned");
 var exceptions : GameObject[];
 var recoveryTime = 10;
 
 private var delay = 0;
 
 
 function Update () {
 
     if (delay>0){delay -=1;}
 
     if (delay==0){
         if(Input.touchCount == 1){
               var currentTouch : Touch = Input.touches[0]; 
 
             if(currentTouch.phase == TouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
                 if (gameObject.CompareTag ("Spawned"))
                     for (var spawined in spawn)
                     {
                            Destroy(GameObject);
                        }
                 }
             }
         }
     }


...any help would translate directly to extra hair on my head.

Thanks heaps.

Comment
Add comment · Show 1
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 syclamoth · Oct 24, 2011 at 09:02 AM 0
Share

Not quite sure I understand this- how does your GUITexture instanitate objects? The GUITexture doesn't do that!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by syclamoth · Oct 24, 2011 at 09:07 AM

Your problem boils down to one letter, actually-

Where you have the line

Destroy(GameObject);

it is trying to destroy the class 'GameObject'- not any particular GameObject, but the entire class. (This makes even less sense than it sounds like).

Instead, you should be using the automatic lookup function to find the attached gameObject-

Destroy(gameObject);

Or, in fact, for that specific case,

Destroy(spawined);

Now, remember that this will only work once, unless you create new objects to fill the gaps which are now left in your array.

There is one other problem, actually- you should be doing the line

spawn = GameObject.FindGameObjectsWithTag("Spawned");

inside of the Start function, not directly under the variable declaration.

Comment
Add comment · 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
0

Answer by siberman · Oct 24, 2011 at 10:43 AM

Hey Mate, thanks for the reply,

Firstly to explain my scene more clearly, there is a script attached to the GUITexture which instantiates 10 instances of a Cube prefab when touched. This second button is meant to kill them all at once, hopefully...

I've made the suggested amendments, and the error message has left, yea, but i'm still not experiencing the poly death i was hoping for. This is with,

Destroy(gameObject);

when i use,

Destroy(spawn);

i get this error

Assets/Scripts/KillSpawned.js(23,12): BCE0023: No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '(UnityEngine.GameObject[])' was found.

I threw in a quick print "kill" to make sure things are above board on that side, and all seems well.

any further ideas?

Cheers.

Comment
Add comment · Show 4 · 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 syclamoth · Oct 24, 2011 at 10:45 AM 1
Share

Sorry, I made a mistake- I meant

 Destroy(spawined);

I forgot which one was the member, and which one was the array!

avatar image siberman · Oct 24, 2011 at 10:09 PM 0
Share

no need to apologise mate, I myself make mistakes every now and then ;)

Unfortunately although the script seems to be 'working' (no errors) it's still not destroying the cubes, it seems as if the array isn't getting populated or something. Is there a way to check this? call and print array members?

Getting there....

avatar image syclamoth · Oct 24, 2011 at 10:29 PM 1
Share

Well, you know that 'for' statement? Try putting a Debug.Log("is it working?"); into it, just before the Destroy line. See if it gets called at all!

Remember that if you use GetComponentsInChildren in Start(), it will only get the objects with that tag in the very first frame. If you want to get everything with that tag in the moment that you need to destroy them, you should put that line just before your for loop, ins$$anonymous$$d!

avatar image siberman · Oct 24, 2011 at 11:48 PM 0
Share

Sweet! Got it!

I moved FindGameObjectsWithTag to just before the for loop as you suggested, and then i deleted "if (gameObject.CompareTag ("Spawned"))" from the same position, as it seemed redundant... more of an instinct call than anything, now working beautifully, Thanks Heaps.

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

How do I destroy a GUI button when I click on it 1 Answer

how can i destroy a cube when i press a gui button??? 1 Answer

Button Turns Off and On Object 1 Answer

Button then instanitates gameobject 1 Answer

How to hook up the particle system to jump animation? 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