Search Unity

problem with naming / getting UI objects in runtime

Discussion in 'UGUI & TextMesh Pro' started by Arakjin, Jan 7, 2020.

  1. Arakjin

    Arakjin

    Joined:
    Nov 12, 2017
    Posts:
    10
    Hi

    I'm having problem with renaming and editing UI objects at runtime, I'm trying to delete "pages" of "book" by looping through them, however when I try to rename pages, it doesn't do it. I don't get any error messages either.
    Also if I try to delete the first child, set all childs active state to false and first child to true it doesn't do it

    To me this looks fine, but for some reason it doesn't work and the question is, why doesn't it work and how to fix it?

    Here's the code:
    Code (CSharp):
    1.     public void DeletePage()
    2.     {
    3.         if (SelectedPage() == null)
    4.         {
    5.             return;
    6.         }
    7.        
    8.         Destroy(SelectedPage());
    9.         if (SelectedSubject().transform.childCount == 0)
    10.         {
    11.             return;
    12.         }
    13.         int i = 1;
    14.         foreach (Transform item in SelectedBook().transform)
    15.         {
    16.             item.gameObject.SetActive(true);
    17.             item.gameObject.name = i.ToString();
    18.             item.gameObject.SetActive(false);
    19.             i++;
    20.         }      
    21.         SelectedBook().transform.GetChild(0).gameObject.SetActive(true);
    22.         PageChanger(0);
    23.     }
    Unity version is 2018.4.14f1