Search Unity

ScrollView stops working when you re-enter the scene

Discussion in 'UGUI & TextMesh Pro' started by Schekhovtsov, Jan 14, 2020.

  1. Schekhovtsov

    Schekhovtsov

    Joined:
    Jan 14, 2020
    Posts:
    17
    Hello. When you re-enter the scene, Scroll View stops working, does not scroll up and down. To fill it, I use the following code in the function:

    Code (CSharp):
    1. void FillList()
    2.     {
    3.         // create instants (level buttons)
    4.         foreach(var level in LevelsList)
    5.         {
    6.             GameObject newbutton = Instantiate(levelButton) as GameObject;
    7.             But_lvlUI button = newbutton.GetComponent<But_lvlUI>();
    8.             button.LevelText.text = level.LevelText;
    9.  
    10.  
    11.             if (PlayerPrefs.GetInt("Level" + button.LevelText.text) == 1)
    12.             {
    13.                 level.Unlocked = 1;
    14.                 level.IsInteractable = true;
    15.             }
    16.  
    17.             button.unlocked = level.Unlocked;
    18.             button.GetComponent<Button>().interactable = level.IsInteractable;
    19.             button.GetComponent<Button>().onClick.AddListener(() => Select_LVL(int.Parse(button.LevelText.text)));
    20.  
    21.             newbutton.transform.SetParent(Spacer);
    22.             newbutton.transform.localScale = new Vector3(1, 1, 1);
    23.             newbutton.transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, 0);
    24.         }
    25.     }
    Can you tell me what could be the problem?