//Actual script
    void InitializeSystemWideParticleEffect()
    {
        //Check to make sure that this is the Ice Age.
        if (CurrentLevelVariableManagement.GetMainGameData().currentLevel == 0)
        {
            //Create the particle effect thing.
            GameObject createdParticleEffectParent = new GameObject("Level Particle Effect");
            createdParticleEffectParent.transform.SetParent(GameObject.Find("Maze").transform);

            //Get level length
            float levelLength         = CurrentLevelVariableManagement.GetLevelLengthX();
            float amountOfAreaToCover = 1.2f * levelLength;

            //Set the position of the particle effect parent.
            createdParticleEffectParent.transform.localPosition = new Vector3(levelLength / 2, 45, 0);

            //The scale of the particle effect.
            float particleEffectScale = 100f / numberOfSegmentsToCreatePer100;

            //For all of the sub-100 segments.  (i.e., 700 width, 7 times).
            for (int i = 0; i < (int)(amountOfAreaToCover / 100f); i++)
            {
                //For all of the particle effects that should be created for each interval of 100.
                for (int j = 0; j < numberOfSegmentsToCreatePer100; j++)
                {
                    //Create a particle effect at some point.
                    //Formula is half the level length (counteract the local position of the parent) + i * numberOfSegmentsToCreatePer100
                    float xPosition = (-amountOfAreaToCover / 2) + (i * numberOfSegmentsToCreatePer100 + j) * (particleEffectScale);

                    //Create the particle effect
                    GameObject createdParticleEffectSegment = (GameObject)(Instantiate(snowParticleEffect, Vector3.zero, snowParticleEffect.transform.localRotation));
                    createdParticleEffectSegment.transform.SetParent(createdParticleEffectParent.transform);
                    createdParticleEffectSegment.transform.localPosition = new Vector3(xPosition, 0, 0);
                    createdParticleEffectSegment.transform.localScale    = new Vector3(particleEffectScale, 1, 1);

                    //Set the emission rate of the particle effect.
                    ParticleSystem.EmissionModule em = createdParticleEffectSegment.GetComponent <ParticleSystem> ().emission;
                    em.rate = new ParticleSystem.MinMaxCurve(particleEffectScale);
                    //Initialize the particle effect.
                    createdParticleEffectSegment.GetComponent <ActivateParticleEffectDependingOnPlayerDistance> ().StartPlayerDistanceChecking();
                }
            }
        }
    }
Ejemplo n.º 2
0
    void CreateBackground()
    {
        float terrainXLength = CurrentLevelVariableManagement.GetLevelLengthX();

        //Layer 1
        layer1Parent = transform.Find("Hill Layer 1");
        int layer1SegmentsToCreate = (int)(terrainXLength * layer1.scrollSpeed) + 4;
        //Instantiate the segments.
        float currentXValue = -layer1.backgrounds[0].bounds.size.x * 2;

        for (int i = 0; i < layer1SegmentsToCreate; i++)
        {
            //Instantiate the panel and set the sprite sorting order.
            GameObject createdPanel = (GameObject)(Instantiate(backgroundPanel, Vector3.zero, Quaternion.identity));
            createdPanel.transform.parent = layer1Parent;
            createdPanel.GetComponent <SpriteRenderer> ().sortingOrder = 0;
            //Choose a sprite and add it to the SpriteRenderer component.
            Sprite chosenSprite = layer1.backgrounds [Random.Range(0, layer1.backgrounds.Length)];
            createdPanel.GetComponent <SpriteRenderer> ().sprite = chosenSprite;
            //Position the sprite accordingly.
            if (i > 0)
            {
                currentXValue += chosenSprite.bounds.size.x / 2f;                    //Only do this on future loops, not the first one.
            }
            createdPanel.transform.localPosition = new Vector3(currentXValue, 0, 0);
            currentXValue += chosenSprite.bounds.size.x / 2f;
        }

        //Layer 2
        layer2Parent = transform.Find("Hill Layer 2");
        int layer2SegmentsToCreate = (int)(terrainXLength * layer2.scrollSpeed) + 4;

        //Instantiate the segments.
        currentXValue = -layer2.backgrounds[0].bounds.size.x * 2;
        for (int i = 0; i < layer2SegmentsToCreate; i++)
        {
            //Instantiate the panel and set the sprite sorting order.
            GameObject createdPanel = (GameObject)(Instantiate(backgroundPanel, Vector3.zero, Quaternion.identity));
            createdPanel.transform.parent = layer2Parent;
            createdPanel.GetComponent <SpriteRenderer> ().sortingOrder = -1;
            //Choose a sprite and add it to the SpriteRenderer component.
            Sprite chosenSprite = layer2.backgrounds [Random.Range(0, layer2.backgrounds.Length)];
            createdPanel.GetComponent <SpriteRenderer> ().sprite = chosenSprite;
            //Position the sprite accordingly.
            if (i > 0)
            {
                currentXValue += chosenSprite.bounds.size.x / 2f;                    //Only do this on future loops, not the first one.
            }
            createdPanel.transform.localPosition = new Vector3(currentXValue, 0, 0);
            currentXValue += chosenSprite.bounds.size.x / 2f;
        }

        //Clouds
        cloudLayerParent = transform.Find("Clouds");
        int cloudLayerSegmentsToCreate = (int)(terrainXLength * clouds.scrollSpeed) + 4;

        //Instantiate the segments.
        currentXValue = -clouds.backgrounds[0].bounds.size.x * 2;
        for (int i = 0; i < cloudLayerSegmentsToCreate; i++)
        {
            //Instantiate the panel and set the sprite sorting order.
            GameObject createdPanel = (GameObject)(Instantiate(backgroundPanel, Vector3.zero, Quaternion.identity));
            createdPanel.transform.parent = cloudLayerParent;
            createdPanel.GetComponent <SpriteRenderer> ().sortingOrder = -2;
            //Choose a sprite and add it to the SpriteRenderer component.
            Sprite chosenSprite = clouds.backgrounds [Random.Range(0, clouds.backgrounds.Length)];
            createdPanel.GetComponent <SpriteRenderer> ().sprite = chosenSprite;
            //Position the sprite accordingly.
            if (i > 0)
            {
                currentXValue += chosenSprite.bounds.size.x / 2f;                    //Only do this on future loops, not the first one.
            }
            createdPanel.transform.localPosition = new Vector3(currentXValue, 0, 0);
            currentXValue += chosenSprite.bounds.size.x / 2f;
        }

        //Background Sky
        backgroundParent = transform.Find("Background");
        int backgroundSegmentsToCreate = (int)(terrainXLength * background.scrollSpeed) + 8;

        //Instantiate the segments.
        currentXValue = -background.backgrounds[0].bounds.size.x * 2;
        for (int i = 0; i < backgroundSegmentsToCreate; i++)
        {
            //Instantiate the panel and set the sprite sorting order.
            GameObject createdPanel = (GameObject)(Instantiate(backgroundPanel, Vector3.zero, Quaternion.identity));
            createdPanel.transform.parent = backgroundParent;
            //Has to go at -4 instead of -3 because the sun has to go behind this layer.
            createdPanel.GetComponent <SpriteRenderer> ().sortingOrder = -4;
            //Choose a sprite and add it to the SpriteRenderer component.
            Sprite chosenSprite = background.backgrounds [Random.Range(0, background.backgrounds.Length)];
            createdPanel.GetComponent <SpriteRenderer> ().sprite = chosenSprite;
            //Position the sprite accordingly.
            if (i > 0)
            {
                currentXValue += chosenSprite.bounds.size.x / 2f;                    //Only do this on future loops, not the first one.
            }
            createdPanel.transform.localPosition = new Vector3(currentXValue, 0, 0);
            currentXValue += chosenSprite.bounds.size.x / 2f;
        }
    }