Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Can't Destroy Objects Found by Tag

Discussion in 'Scripting' started by yangmeng, Jun 21, 2007.

  1. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    I am instantiating a bunch of projectiles that I want to destroy at certain intervals and thought I could do it with this script, but Unity is objecting about argument lists.
    Anyone know how I need to change this? Thanks.

    Code (csharp):
    1.         objects = GameObject.FindGameObjectsWithTag("proj");
    2.         Destroy(objects);
    3.  
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Destroy() takes a single object; and what you're passing is an array of them. Try something like this instead (not tested):
    Code (csharp):
    1. objects = GameObject.FindGameObjectsWithTag("proj");
    2. for( var o in objects )
    3.     Destroy(o);
     
  3. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    That did it. I didn't realize "Destroy" was a single-object action. Good to have a solution to that! Thanks.