0

I'm not having trouble of deleting the children of the other statements but this 1 statement is pretty weird.

Here's is my code of deleting the children in NGUI

void DeleteChildrens(Transform t)
{
    NGUITools.DestroyChildren(t);
}

Now here is how I'm using it .

[SerializeField] Transform[] pos_big_road = null;
[SerializeField] Transform[] pos_bead_road = null;
[SerializeField] Transform[] pos_big_eye_road = null;

private myFunction(bool success, ...){

    if(g-number == 1){

       DeleteChildrens(pos_big_road[0]); //--> THIS IS HOW I USE THE DeleteChildrens().
       DeleteChildrens(pos_bead_road[0]);

      //first statement met successfully
      foreach(string previousValue in newChars){
         GameObject bigroad = Instantiate(prefab_big_road[0]) as GameObject;
         bigroad.transform.SetParent(pos_big_road[0]);
         bigroad.transform.localScale = Vector3.one
      }
      //second statement met successfully
      foreach(string previousValue2 in newChars){
         GameObject beadroad = Instantiate(prefab_bead_road[0]) as GameObject;
         beadroad.transform.SetParent(pos_bead_road[0]);
         beadroad.transform.localScale = Vector3.one;
      }
    }

}

Those 2 foreach() statement is working properly and the children can be deleted smoothly.

What I am trying to do here is like a refresh functionality by the way.

And now here is my messed up part that DeleteChildrens() behaves not like I am expecting to do.

[SerializeField] Transform[] pos_big_road = null;
[SerializeField] Transform[] pos_bead_road = null;
[SerializeField] Transform[] pos_big_eye_road = null;

private myFunction(bool success, ...){

    if(g-number == 1){

       DeleteChildrens(pos_big_road[0]); //--> THIS IS HOW I USE THE DeleteChildrens().
       DeleteChildrens(pos_bead_road[0]);

      //first statement met successfully
      foreach(string previousValue in newChars){
         GameObject bigroad = Instantiate(prefab_big_road[0]) as GameObject;
         bigroad.transform.SetParent(pos_big_road[0]);
         bigroad.transform.localScale = Vector3.one
      }
      //second statement met successfully
      foreach(string previousValue2 in newChars){
         GameObject beadroad = Instantiate(prefab_bead_road[0]) as GameObject;
         beadroad.transform.SetParent(pos_bead_road[0]);
         beadroad.transform.localScale = Vector3.one;
      }
    }
    //The messed up part
  for (int col = 0; col < table.GetLength(0); col++)
  {
       for (int row = 0; row < table.GetLength(1); row++)
       {
             //more codes here
       }
   }
   if (redBead)
   {
       if (isWholeColumnNull)
       {
           NGUITools.SetActive(p, false);
       }
       else
       {
            p = Instantiate(prefab_big_eye_road[0]) as GameObject;
            p.transform.SetParent(pos_big_eye_road[0]);
            p.transform.localScale = Vector3.one;

            p.GetComponent<UISprite>().spriteName = "symble_banker_bigroad-bigeyeroad";
            NGUITools.SetActive(p, true);
       }
   }

   if (blueBead)
   {
       if (isWholeColumnNull)
       {
           NGUITools.SetActive(p, false);
       }
       else
       {
            p = Instantiate(prefab_big_eye_road[0]) as GameObject;
            p.transform.SetParent(pos_big_eye_road[0]);
            p.transform.localScale = Vector3.one;

            p.GetComponent<UISprite>().spriteName = "symble_player_bigroad-bigeyeroad";
            NGUITools.SetActive(p, true);
       }
   }

}

When I am trying to put this code above together with the other

DeleteChildrens(pos_big_road[0]);
DeleteChildrens(pos_bead_road[0]);
DeleteChildrens(pos_big_eye_road[0]);

This

DeleteChildrens(pos_big_eye_road[0]);

Is just deleting the children and never Instantiate again Unlike the the other 2 statement . What could be the problem? Could someone point it out to me :)

Ginxxx
  • 1,602
  • 2
  • 25
  • 54

0 Answers0