Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LevelGenerator : MonoBehaviour {
  6.  
  7.     public float GenerateStep;
  8.     public LevelObject[] Objects;
  9.     public Transform player;
  10.     public float XLeft;
  11.     public float XRight;
  12.  
  13.     private float generationY = 0;
  14.     private float YOffset = 5;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.        
  19.     }
  20.    
  21.     // Update is called once per frame
  22.     void Update () {
  23.        
  24.         if (generationY <= player.position.y)
  25.         {
  26.             Generate();
  27.             generationY += GenerateStep;
  28.         }
  29.     }
  30.  
  31.     private void Generate()
  32.     {
  33.        
  34.        
  35.        
  36.  
  37.          for(int i = 0; i < Objects.Length; i++)
  38.          {
  39.             Vector3 spawnPos = new Vector3(0, player.position.y +YOffset);
  40.             if (Objects[i].Rarity >= 1)
  41.             {
  42.                 for (int a = 0; a < Objects[i].Rarity; a++)
  43.                 {
  44.                     spawnPos.y += Random.Range(0.1f, Objects[i].MaximalDistanse);
  45.                     spawnPos.x = Random.Range(XLeft, XRight);
  46.  
  47.                     Instantiate(Objects[i].obj, spawnPos,Quaternion.identity);
  48.                    
  49.                 }
  50.                
  51.             }
  52.             else
  53.             {
  54.  
  55.             }
  56.            
  57.          }
  58.  
  59.     }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. using System.Collections;
  73. using System.Collections.Generic;
  74. using UnityEngine;
  75. [System.Serializable]
  76. public class LevelObject {
  77.  
  78.     public GameObject obj;
  79.     public float MaximalDistanse;
  80.     public float Rarity;
  81.  
  82.     // Use this for initialization
  83.     void Start () {
  84.        
  85.     }
  86.    
  87.     // Update is called once per frame
  88.     void Update () {
  89.        
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement