// Initialization - choose and prepare the mask that will be assembled by the player void Start() { // Choose a random mask chosenMask = maskPrefabs[Random.Range(0, maskPrefabs.Length)]; GameObject chosenMaskFragmented = Instantiate( chosenMask.fragmented, Vector2.zero, Quaternion.identity ); print("Chosen " + chosenMaskFragmented.name + ". It has " + chosenMaskFragmented.transform.childCount + " fragments."); // Get info about the edges that should be connected edges = chosenMaskFragmented.GetComponent <MaskPuzzleMaskEdges>(); // Layers will be assigned starting from this one int layerCounter = FIRST_MASK_LAYER; // Initialize all fragments of the chosen mask while (chosenMaskFragmented.transform.childCount > 0) { GameObject currentFragment = chosenMaskFragmented.transform.GetChild(0).gameObject; print("Taking " + currentFragment.name + " from the library"); // Become the parent of the fragment currentFragment.transform.parent = transform; // Randomize the spawn location int spawnPointIndex = Random.Range(0, spawnCoordinates.Count); currentFragment.transform.position = spawnCoordinates[spawnPointIndex]; spawnCoordinates.RemoveAt(spawnPointIndex); // Add script and collider to the fragment currentFragment.GetComponent <MaskPuzzleMaskFragment>().fragmentsManager = this; currentFragment.AddComponent <MeshCollider>(); // Assign a layer to the fragment currentFragment.gameObject.layer = layerCounter++; // Add the fragment to list fragments.Add(currentFragment.GetComponent <MaskPuzzleMaskFragment>()); } }
// Initialization - choose and prepare the mask that will be assembled by the player // as well as the background and victory position void Start() { // Choose a random mask chosenMask = maskPrefabs[Random.Range(0, maskPrefabs.Length)]; GameObject chosenMaskFragmented = Instantiate( chosenMask.fragmented, Vector2.zero, Quaternion.identity ); print("Chosen " + chosenMaskFragmented.name + ". It has " + chosenMaskFragmented.transform.childCount + " fragments."); // Get info about the edges that should be connected edges = chosenMaskFragmented.GetComponent <MaskPuzzleMaskEdges>(); // Layers will be assigned starting from this one int layerCounter = FIRST_MASK_LAYER; // Initialize all fragments of the chosen mask while (chosenMaskFragmented.transform.childCount > 0) { GameObject currentFragment = chosenMaskFragmented.transform.GetChild(0).gameObject; print("Taking " + currentFragment.name + " from the library"); // Become the parent of the fragment currentFragment.transform.parent = transform; // Randomize the spawn location int spawnPointIndex = Random.Range(0, spawnCoordinates.Count); currentFragment.transform.position = spawnCoordinates[spawnPointIndex]; spawnCoordinates.RemoveAt(spawnPointIndex); // Add script and collider to the fragment currentFragment.GetComponent <MaskPuzzleMaskFragment>().fragmentsManager = this; currentFragment.AddComponent <MeshCollider>(); // Assign a layer to the fragment currentFragment.gameObject.layer = layerCounter++; // Add the fragment to list fragments.Add(currentFragment.GetComponent <MaskPuzzleMaskFragment>()); } // Choose a random background, ensure it's the only one visible, // and copy its victory position values if (backgroundVariants.Length > 0) { Background chosenBackground = backgroundVariants[Random.Range(0, backgroundVariants.Length)]; foreach (Background backgroundVariant in backgroundVariants) { if (backgroundVariant.backgroundImage != chosenBackground.backgroundImage) { backgroundVariant.backgroundImage.SetActive(false); } } chosenBackground.backgroundImage.SetActive(true); victoryGoal = chosenBackground.victoryGoal; victoryRotation = chosenBackground.victoryRotation; } }