Search Unity

Create World to Levels with Json Data

Discussion in 'Scripting' started by Shinsuki93, Nov 27, 2017.

  1. Shinsuki93

    Shinsuki93

    Joined:
    Aug 11, 2017
    Posts:
    38
    Hello,

    I'm trying to do a game with levels but all the 20 levels I want a new "world". (Like Cut the Rope or Angry Birds)
    I have all LevelsData in ma .json ( level 1 to 100 ).

    How can I load for example level 1 at 20 to one world in my menu level selection ? ( In screenshot the Example I want to reach..)

    Thanks you very much for your help and time.

    Best regards,
    Shinsuki
     

    Attached Files:

  2. irisp

    irisp

    Joined:
    Nov 28, 2017
    Posts:
    2
  3. Shinsuki93

    Shinsuki93

    Joined:
    Aug 11, 2017
    Posts:
    38
    Hello,

    Thanks for you're response, but I think I am not clear..
    I have my Json data with all my 100 levels, but I want in Screen the first when you're in the game, The world, like "Forest", 2 world : "City", etc.. etc... And when you enter in the world "Forest" you see all the 1-20 levels

    Like all the game with levels (Cut the Rope, Angry birds, etc...) but I don't see how I can put that...

    Thanks you very much for your help.

    Best regards,
    Shinsuki
     
  4. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    What were you creating your json files with? Are all the levels in one big file, or there are multiple files one per level?

    You could probably use JsonUtility to load level data.
     
  5. laxbrookes

    laxbrookes

    Joined:
    Jan 9, 2015
    Posts:
    235
    You'll need to create a custom class that your JSON can map to. You can then map to it with the built in JSON utilities.
     
  6. Shinsuki93

    Shinsuki93

    Joined:
    Aug 11, 2017
    Posts:
    38
    Code (csharp):
    1.  
    2.  
    3. // Generate the level group each level group at 20 levels
    4.         for (int i = 1; i <= levelgroupNumber; i++)
    5.         {
    6.             GameObject buttonGroup = Instantiate(buttonGroupPrefab, levelDetailContent.transform.position, Quaternion.identity) as GameObject;
    7.             buttonGroup.transform.SetParent(levelDetailContent.transform);
    8.             buttonGroup.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
    9.  
    10.             int childCount = 0;
    11.             for (int j = count; j < buttonGroup.transform.childCount * i; j++)
    12.             {
    13.                 if (j >= data.Length)
    14.                 {
    15.                     buttonGroup.transform.GetChild(childCount).gameObject.SetActive(false);
    16.                 }
    17.                 else
    18.                 {
    19.                     LevelData levelData = JsonUtility.FromJson<LevelData>(data[j]);
    20.                     Transform theChild = buttonGroup.transform.GetChild(childCount);
    21.                     theChild.GetComponentInChildren<Text>().text = levelData.levelNumber.ToString();
    22.  
    23.                     LevelButtonController levelButtonController = theChild.GetComponent<LevelButtonController>();
    24.                     GameObject lockOb = theChild.Find("Lock").gameObject;
    25.                     GameObject imgSolvedOb = theChild.Find("imgSolved").gameObject;
    26.                     Image levelImg = theChild.Find("Mask").Find("Image").GetComponent<Image>();
    27.                     RectTransform levelImgRT = levelImg.GetComponent<RectTransform>();
    28.  
    29.  
    But I see the Screenshot i've made, I don't want that, but put an different image for all the "World"

    Thanks you very much for you're help really.

    Best regards,
    Shinsuki