//Helping Method private void CreateInactiveLetter(Transform position) { int positionInArray = Random.Range(0, 3); Target2P inactiveLetterClone = Instantiate(inactiveLettersArray[positionInArray], position.position, transform.rotation); inactiveLetterClone.transform.SetParent(this.transform); inactiveLetterClone.SetIsTheRightTarget(false); /*Target2P inactiveLetterCloneTarget = inactiveLetterClone.GetComponent<Target2P>(); * inactiveLetterCloneTarget.SetLineAndTargetID(lineAndTargetID);*/ }
//Gets and instantiates active and inactive letter objects from GameManager void Start() { gameManager = FindObjectOfType <GameManager>(); activeLetter = gameManager.ReturnActiveLetter(); activeLetter.SetIsTheRightTarget(true); inactiveLettersArray = gameManager.ReturnInactiveLetters(); //Set number of 'active letters' in the current LetterLine instance (min = 1, max = 3) numOfActiveLetters = Random.Range(1, 4); numberOfInstances += numOfActiveLetters; gameManager.IncrementTargetsSpawned(numOfActiveLetters); if (numberOfInstances == 10) { numberOfInstances = 0; ///////////////////////////////////// Debug.Log("Count : " + count); count++; ///////////////////////////////////// } else if (numberOfInstances > 10) { TryAgain(); } // Instantiate randomly letters accros letterLine so that there is a corresponding number of 'active' letters to the number above, others must be 'inactive' while (countSpawnedActiveLetters < numOfActiveLetters) { for (int x = 0; x < usedPositions.Length; x++) { // Returns random bool value bool randomBool = (Random.value > 0.5f); if (randomBool && countSpawnedActiveLetters < numOfActiveLetters && !usedPositions[x]) { usedPositions[x] = true; CreateActiveLetter(spawnerPos[x]); countSpawnedActiveLetters++; } } } // Fill the rest of the positions with inactive letters for (int x = 0; x < usedPositions.Length; x++) { if (!usedPositions[x]) { CreateInactiveLetter(spawnerPos[x]); } } }