Пример #1
0
    private void Start()
    {
        for (int i = 0; i < maxClouds; i++)
        {
            GameObject newCloud = Instantiate(cloudPrefabs [Mathf.RoundToInt(Random.Range(0f, cloudPrefabs.Length - 1))],
                                              new Vector3((Random.Range(0f, xBound)) + transform.position.x, transform.position.y + Random.Range(-yRange, yRange), 0f), transform.rotation, gameObject.transform);

            // Try to set the sorting layer and order in layer for the new cloud
            try {
                newCloud.GetComponent <SpriteRenderer> ().sortingLayerName = cloudLayer;
            } catch {
                Debug.Log("Invalid Sorting Layer name");
            }
            newCloud.GetComponent <SpriteRenderer> ().sortingOrder = orderInLayer;

            newCloud.GetComponent <SpriteRenderer> ().color = cloudColor;

            if (newCloud.GetComponent <CloudBehavior> () != null)
            {
                // Set the vars to the CloudBehavior component of the new cloud
                CloudBehavior newCloudBehav = newCloud.GetComponent <CloudBehavior> ();
                newCloudBehav.cloudGenerator = this.gameObject;
                newCloudBehav.speed          = Random.Range(minSpeed, maxSpeed);
                newCloudBehav.scale          = Random.Range(minScale, maxScale);
                newCloudBehav.xBound         = xBound;
            }
            else
            {
                // Set the vars to the StormyCloudBehavior component of the new cloud
                StormyCloudBehavior newCloudBehav = newCloud.GetComponent <StormyCloudBehavior> ();
                newCloudBehav.cloudGenerator = this.gameObject;
                newCloudBehav.speed          = Random.Range(minSpeed, maxSpeed);
                newCloudBehav.scale          = Random.Range(minScale, maxScale);
                newCloudBehav.xBound         = xBound;
            }

            childClouds.Add(newCloud);
            ++numberOfClouds;             // Increase the number of clouds by 1
        }
    }
Пример #2
0
    private void Update()
    {
        // If the max number of clouds isn't onscreen, spawn one and set its properties
        if (numberOfClouds <= maxClouds)
        {
            GameObject newCloud = Instantiate(cloudPrefabs [Mathf.RoundToInt(Random.Range(0f, cloudPrefabs.Length - 1))],
                                              new Vector3(transform.position.x, transform.position.y + Random.Range(-yRange, yRange), 0f), transform.rotation, gameObject.transform);

            // Try to set the sorting layer and order in layer for the new cloud
            try {
                newCloud.GetComponent <SpriteRenderer> ().sortingLayerName = cloudLayer;
            } catch {
                Debug.Log("Invalid Sorting Layer name");
            }
            newCloud.GetComponent <SpriteRenderer> ().sortingOrder = orderInLayer;

            newCloud.GetComponent <SpriteRenderer> ().color = cloudColor;

            if (newCloud.GetComponent <CloudBehavior> () != null)
            {
                // Set the vars to the CloudBehavior component of the new cloud
                CloudBehavior newCloudBehav = newCloud.GetComponent <CloudBehavior> ();
                newCloudBehav.cloudGenerator = this.gameObject;
                newCloudBehav.speed          = Random.Range(minSpeed, maxSpeed);
                newCloudBehav.scale          = Random.Range(minScale, maxScale);
                newCloudBehav.xBound         = xBound;
            }
            else
            {
                // Set the vars to the StormyCloudBehavior component of the new cloud
                StormyCloudBehavior newCloudBehav = newCloud.GetComponent <StormyCloudBehavior> ();
                newCloudBehav.cloudGenerator = this.gameObject;
                newCloudBehav.speed          = Random.Range(minSpeed, maxSpeed);
                newCloudBehav.scale          = Random.Range(minScale, maxScale);
                newCloudBehav.xBound         = xBound;
            }

            childClouds.Add(newCloud);
            ++numberOfClouds;             // Increase the number of clouds by 1
        }


        if (timeController != null)           // I put this line in so that you don't have to use the time controller
        {
            if (timeController.GetComponent <TitlescrnTimeHandler> ().currentState == TitlescrnTimeHandler.DayState.NOON)
            {
                foreach (GameObject cloud in childClouds)
                {
                    cloud.GetComponent <CloudBehavior> ().isNoon = true;
                }
            }
            else
            {
                foreach (GameObject cloud in childClouds)
                {
                    cloud.GetComponent <CloudBehavior> ().isNoon = false;
                }
            }
        }
        else
        {
            if (triggerNoonClouds)
            {
                foreach (GameObject cloud in childClouds)
                {
                    if (cloud.GetComponent <CloudBehavior> () != null)
                    {
                        cloud.GetComponent <CloudBehavior> ().isNoon = true;
                    }
                }
            }
            else
            {
                foreach (GameObject cloud in childClouds)
                {
                    if (cloud.GetComponent <CloudBehavior> () != null)
                    {
                        cloud.GetComponent <CloudBehavior> ().isNoon = false;
                    }
                }
            }
        }
    }