Search Unity

Question Objects not getting destroyed

Discussion in 'Windows' started by nettik123, Feb 1, 2021.

  1. nettik123

    nettik123

    Joined:
    Feb 1, 2021
    Posts:
    1
    I destroy objects with certain tag except one, but they're not getting destroyed.

    Code (CSharp):
    1. smieci = GameObject.FindGameObjectsWithTag("Respawn");
    2.         Debug.Log("pl " + smieci.Length);
    3.         for (int i = 0; i < smieci.Length; i++) { smieci[i].GetComponent<RuchBlok>().dest();  }
    4.         if (this.GetComponent<Timer>().gracz() == 1)
    5.         {
    6.             if (this.GetComponent<SzachMatPat>().szach(krow, 0, 1))
    7.             {
    8.                 this.GetComponent<SzachMatPat>().matpat(0);
    9.             }
    10.         }
    Code (CSharp):
    1. public bool matpat(int czarny)
    2.     {
    3.         if (Gra.GetComponent<Timer>().gracz() > 0)
    4.         {
    5.             GameObject[] smiec = GameObject.FindGameObjectsWithTag("Respawn");
    6.             Debug.Log("mp " + smiec.Length);
    7.             GameObject[] piony = GameObject.FindGameObjectsWithTag("Player");
    8.         }
    9.     }
    Code (CSharp):
    1. public void dest()
    2.     {
    3.         if (transform.position.x < 10)
    4.         {
    5.             Debug.Log("dest");
    6.             Destroy(gameObject);
    7.         }
    8.     }
    In the console i get:
    pl 5 (5 objects exist)
    dest
    dest
    dest
    dest (destroying the four objects)
    mp 5 (still 5 objects remaining)

    I can't find where I get it wrong.