Esempio n. 1
0
    // 2 random numbers have been generated to decide which element spawns and what lane it is spawned into.

    // Given the random element and location this method will Instantiate a prefab or that element into that lane.
    private void createNewUnit()
    {
        generateLaneAndElem();
        animators [randomSpawnedLane].SetTrigger("spawning");
        //checks whether its going to be another element and not a powerup
        if (forceCorrectSpawnInLane[randomSpawnedLane] && randomSpawnedElement != GlobalVars.NUMBER_OF_LANES)
        {
            //sets the element to be of the correct type (if it's not a powerup)
            randomSpawnedElement = randomSpawnedLane;
        }
        //if we're spawning a powerup
        if (randomSpawnedElement == GlobalVars.NUMBER_OF_LANES)
        {
            //calls the event
            if (OnSpawnPowerUp != null)
            {
                OnSpawnPowerUp();
            }
            //increases the count
            GlobalVars.POWERUP_SPAWN_COUNT++;
        }
        // INSTANTIATE
        if (PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0 && !GlobalVars.SWIPE_TUTORIAL_FIRST_SPAWNED)
        {
            spawnedElement      = (GameObject)Instantiate(elements [1], lanes [0], Quaternion.identity);
            spawnedElement.name = GlobalVars.SWIPE_TUTORIAL_ELEMENT_NAME;
            GlobalVars.SWIPE_TUTORIAL_FIRST_SPAWNED = true;
        }
        else
        {
#if DEBUG
//		randomSpawnedElement = GlobalVars.NUMBER_OF_LANES;
//		Debug.Log("setting the game to only spawn powerups");
#endif
            spawnedElement = (GameObject)Instantiate(elements [randomSpawnedElement], lanes [randomSpawnedLane], Quaternion.identity);
        }
        // Catching the first element to spawn and stops spawning so we can show a tutorial.
        if (!hasTutorialElementSpawned && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0)
        {
            spawning        = false;
            tutorialElement = spawnedElement;
            tutorialElement.GetComponent <Collider>().enabled = false;
            hasTutorialElementSpawned = true;
            timeToPowerUp             = true;
        }
        if (!isSecondElementGiven && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0)
        {
            spawning        = false;
            tutorialElement = spawnedElement;
        }
        if (randomSpawnedElement == GlobalVars.NUMBER_OF_LANES)
        {
            spawnedElement.SetActive(true);
        }
        spawnedElement.AddComponent <MoveElementDown>();
        spawnedElement.AddComponent <MoveElementUp> ();
        spawnedElement.GetComponent <MoveElementUp> ().enabled = false;
        ZoneCollisionDetection.addToOnScreenElements(spawnedElement);
    }
Esempio n. 2
0
 // A function to spawn in the second tutorial element.
 public void SpawnInSecondSwipeTutorialElement()
 {
     spawnedElement = (GameObject)Instantiate(elements [3], lanes [0], Quaternion.identity);
     GlobalVars.SWIPE_TUTORIAL_SECOND_SPAWNED = true;
     spawning        = false;
     tutorialElement = spawnedElement;
     tutorialElement.GetComponent <Collider>().enabled = false;
     tutorialElement.name = GlobalVars.SWIPE_TUTORIAL_SECOND_ELEMENT_NAME;
     spawnedElement.AddComponent <MoveElementDown>();
     spawnedElement.AddComponent <MoveElementUp> ();
     spawnedElement.GetComponent <MoveElementUp> ().enabled = false;
     ZoneCollisionDetection.addToOnScreenElements(spawnedElement);
     SecondElementHasBeenSpawned();
 }
    // The choices must be buckets that are beside each other.

    // This method is given the 2 lanes choosen to be spawned.
    void MoveElementsOnScreenUp()
    {
        // Stop the CollectionTimer script from counting down while a swap is happening.
        this.GetComponent <CollectionTimer> ().SetIsCountingDown(false);
        this.GetComponent <GenerationScript> ().SetSpawning(false);
        for (int i = 0; i < 4; i++)
        {
            antiGravAnimators [i].SetTrigger("preSwapping");
        }
        foreach (GameObject elementInLane in ZoneCollisionDetection.GetOnScreenElements())
        {
            if (elementInLane != null)
            {
                elementInLane.GetComponent <MoveElementDown>().enabled = false;
                elementInLane.GetComponent <MoveElementUp>().enabled   = true;
                StartCoroutine(WaitBeforeResetComponents());
            }
        }
    }