Example #1
0
    public static LadyBugController PassParameters(GameObject where, Vector3 pfPosition, float pfSize)
    {
        LadyBugController myLadyBugController = where.GetComponent <LadyBugController>();

        myLadyBugController.platformPosition = pfPosition;
        myLadyBugController.platformSize     = pfSize;
        myLadyBugController.rightCorner      = new Vector3(pfPosition.x + 100f, pfPosition.y + 1f, pfPosition.z);
        myLadyBugController.leftCorner       = new Vector3(pfPosition.x - 100f, pfPosition.y + 1f, pfPosition.z);
        return(myLadyBugController);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < generationPoint.position.x)
        {
            int level = Random.Range(0, 3);

            if (level != prevLevel)
            {
                curSameLevelNum = 1;
            }
            else if (curSameLevelNum < maxSameLevelNum)
            {
                curSameLevelNum++;
            }
            else
            {
                while (level == prevLevel)
                {
                    level = Random.Range(0, 2);
                }
                curSameLevelNum = 1;
            }
            if (prevLevel == level || isFirstGround)
            {
                distanceBetween = Random.Range(1.5f, distanceBetweenMax);
                isFirstGround   = false;
            }
            else
            {
                distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);
            }

            prevLevel = level;

            //level = 2;

            platformSelector = platformByLevel[level][Random.Range(0, platformByLevel[level].Count)];


            heightChange = (float)(level - 1) * heightLevel + heightOffset;

            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + distanceBetween,
                                             heightChange, transform.position.z);

            GameObject newPlatform = theObjectPools[platformSelector].GetPooledObject();
            newPlatform.transform.position = new Vector3(
                transform.position.x,
                heightChange - platformHeights[platformSelector] / 2,
                transform.position.z
                );
            newPlatform.transform.rotation = transform.rotation;
            newPlatform.SetActive(true);

            Vector3 ladyBugPositionOffset = new Vector3(0f, 0.6f, 0f);
            Vector3 coinPositionOffset    = new Vector3(0f, 1f, 0f);


            if (Random.Range(0f, 100f) < randomCoinThreshold)
            {
                theCoinGenerator.SpawnCoins(
                    transform.position + coinPositionOffset,
                    platformWidths[platformSelector],
                    newPlatform.GetComponent <Renderer>().bounds);
            }

            if (platformSelector == 4 || platformSelector == 5)
            {
                GameObject ropeLeft = ropePool.GetPooledObject();
                ropeLeft.SetActive(true);
                GameObject ropeRight = ropePool.GetPooledObject();
                ropeRight.SetActive(true);

                float xOffset = platformWidths [platformSelector] / 2 - 0.1f;
                float yOffset = 3;

                ropeLeft.transform.position  = transform.position + new Vector3(-xOffset, yOffset, 0);
                ropeRight.transform.position = transform.position + new Vector3(xOffset, yOffset, 0);
            }


            if (platformWidths [platformSelector] > 5.2f)
            {
                if (Random.Range(0f, 100f) < randomSniperThreshold)
                {
                    GameObject newSniper = sniperPool.GetPooledObject();

                    float   sniperXPositionOffset = Random.Range(0f, platformWidths[platformSelector] / 2);
                    Vector3 sniperPositionOffset  = new Vector3(sniperXPositionOffset, 1f, 0f);
                    newSniper.transform.position = transform.position + sniperPositionOffset;
                    newSniper.transform.rotation = transform.rotation;
                    newSniper.SetActive(true);
                }
                else if (Random.Range(0f, 100f) < randomLadyBugThreshold)
                {
                    GameObject newLadyBug = ladyBugPool.GetPooledObject();


                    newLadyBug.transform.position = transform.position + ladyBugPositionOffset;
                    newLadyBug.transform.rotation = transform.rotation;

                    // pass the parameters used for moving the ladybugs.
                    LadyBugController.PassParameters(newLadyBug, newPlatform.transform.position,
                                                     newPlatform.GetComponent <BoxCollider2D> ().size.x);
                    newLadyBug.SetActive(true);
                }
            }


            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2),
                                             transform.position.y, transform.position.z);
        }
    }