Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Delete all was working and now it isn't any help?

Discussion in '2D' started by erumi321, Feb 22, 2020.

  1. erumi321

    erumi321

    Joined:
    May 26, 2019
    Posts:
    3
    So I have this code

    Code (CSharp):
    1.    GameObject[] allObjects = GameObject.FindGameObjectsWithTag("ButtonToGetRidOf");
    2.         foreach (GameObject obj in allObjects)
    3.         {
    4.             Destroy(obj);
    5.         }
    and it was working but now it isn't. I have a button that I want to delete but there can be multiple so I want to delete all of them. It was working and now it isn't.
     
  2. erumi321

    erumi321

    Joined:
    May 26, 2019
    Posts:
    3
    Nevermind, got it.
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @erumi321

    "Nevermind, got it."


    Not very helpful - usually it is polite to add an answer even if you solved the problem yourself...

    In case of deleting something from a list - use for loop instead of for each.