Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CloudSpawner : MonoBehaviour {
- [SerializeField]
- private GameObject[] clouds;
- [SerializeField]
- private GameObject[] collectables;
- private float distanceBetweenClouds = 3f;
- private float minX, maxX;
- private float lastCloudPositionY;
- private float controlX;
- private GameObject player;
- void Awake() {
- SetMinAndMaxX ();
- }
- // Use this for initialization
- void Start () {
- }
- void SetMinAndMaxX() {
- Vector3 bounds = Camera.main.ScreenToWorldPoint (new Vector3 (0,0,0));
- //this gives you the world space coordinate of the bottom left of the screen
- // which will be a negative number as the centre of the camera is located at 0 X axis.
- maxX = -bounds.x - 0.5f; // by using - bounds we make this a positive coordinate on teh x acis eg; 3
- minX = bounds.x + 0.5f; // because the X coordinate returned from ScreenToWorldPoint was negative we don't need to change this
- }
- void Shuffle(GameObject[] arrayToShuffle) {
- for (int i=0; i < arrayToShuffle.Length; i++) {
- GameObject temp = arrayToShuffle[i];
- int random = Random.Range(i, arrayToShuffle.Length);
- arrayToShuffle[i] = arrayToShuffle[random];
- arrayToShuffle[random] = temp;
- }
- }
- void CreateClouds() {
- Shuffle (clouds);
- float positionY = 0f;
- for (int i=0; i < clouds.Length; i++) {
- Vector3 temp = clouds[i].transform.position;
- temp.y = positionY;
- if(controlX == 0) {
- temp.x = Random.Range(0.0f, maxX);
- controlX = 1;
- } else if (controlX == 1) {
- temp.x = Random.Range(0.0f, maxX);
- controlX = 2;
- } else if (controlX == 2) {
- temp.x = Random.Range(0.0f, maxX);
- controlX = 3;
- } else if (controlX == 3) {
- temp.x = Random.Range(0.0f, maxX);
- controlX = 0;
- }
- lastCloudPositionY = positionY;
- clouds[i].transform.position = temp;
- positionY -= distanceBetweenClouds;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement