示例#1
0
    void Start()
    {
        GlobalFunctions.isLoading = false;
        if (qa != null)
        {
            if (qa.GetBank().Count == 0)
            {
                qa.Load();
                qa = qa.GetBank()[level - 1];
            }
        }
        isFinished   = false;
        showQuestion = false;
        input        = "";
        isNotRandom  = true;
        gameTime     = 0;

        if (canvas.activeInHierarchy)
        {
            canvas.SetActive(!canvas.activeInHierarchy);                                                //set the menu canvas to inactive
        }
        isNotRandom = true;                                                                             // Reset the puzzle random state to not random yet.
        GameObject Puzzle = GameObject.Find("Puzzle");                                                  //Find the Puzzle Game object

        PuzzlePieces = Puzzle.GetComponentsInChildren <Transform>();                                    //Transforms property of each puzzle pieces
        int ctr = 0;                                                                                    //A counter

        Texture2D[] images = Resources.LoadAll <Texture2D>("UI/Images/Hard/Level/" + level.ToString()); //Load all images based on level
        images.OrderBy(x => x.name);
        Transform[] PuzzlePiecesHelp = PuzzleHelp.GetComponentsInChildren <Transform>();
        foreach (Transform go in PuzzlePiecesHelp)
        {
            if (go.name != "PuzzleHelp")
            {
                if (ctr <= images.Length - 2)
                {
                    go.GetComponentInChildren <Renderer>().material.mainTexture = images[ctr];
                }
                else
                {
                }
                ctr++;
            }
        }

        ctr = 0;

        foreach (Transform go in PuzzlePieces)
        {
            if (go.name != "Puzzle")
            {
                go.gameObject.AddComponent <PuzzlePieceScript>();
                go.gameObject.GetComponent <PuzzlePieceScript>().isDoneRandomizing = false;
                if (ctr <= images.Length - 2)
                {
                    go.GetComponentInChildren <Renderer>().material.mainTexture = images[ctr];
                }
                else
                {
                    go.gameObject.GetComponent <PuzzlePieceScript>().isNullPiece = true;
                    nullPiece = go.gameObject;
                }
                ctr++;
            }
        }
    }