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 LevelGenerator : MonoBehaviour {
- public float GenerateStep;
- public LevelObject[] Objects;
- public Transform player;
- public float XLeft;
- public float XRight;
- private float generationY = 0;
- private float YOffset = 5;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (generationY <= player.position.y)
- {
- Generate();
- generationY += GenerateStep;
- }
- }
- private void Generate()
- {
- for(int i = 0; i < Objects.Length; i++)
- {
- Vector3 spawnPos = new Vector3(0, player.position.y +YOffset);
- if (Objects[i].Rarity >= 1)
- {
- for (int a = 0; a < Objects[i].Rarity; a++)
- {
- spawnPos.y += Random.Range(0.1f, Objects[i].MaximalDistanse);
- spawnPos.x = Random.Range(XLeft, XRight);
- Instantiate(Objects[i].obj, spawnPos,Quaternion.identity);
- }
- }
- else
- {
- }
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [System.Serializable]
- public class LevelObject {
- public GameObject obj;
- public float MaximalDistanse;
- public float Rarity;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement