Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Trying to increase number more than 1. please help!

Discussion in 'Scripting' started by Ncon123, Aug 22, 2015.

  1. Ncon123

    Ncon123

    Joined:
    May 6, 2015
    Posts:
    25
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Generation : MonoBehaviour
    5. {
    6.     public float X = 0;
    7.     public float Y = 0;
    8.     public float Z = 0;
    9.  
    10.     public GameObject Grass;
    11.     public GameObject Stone;
    12.     public GameObject Bedrock;
    13.  
    14.     public int BlockNumber = 0;
    15.  
    16.     public int Rand;
    17.     public float RandY;
    18.     public int LastY = 0;
    19.     public int Last;
    20.    
    21.     void Start ()
    22.     {
    23.         GenerateChunk ();
    24.         RandY = Y + Rand;
    25.         LastY = 0;
    26.     }
    27.    
    28.     void GenerateStone()
    29.     {
    30.         Instantiate (Stone, new Vector3 (X, RandY, Z), Quaternion.identity);
    31.     }
    32.    
    33.     void GenerateGrass()
    34.     {
    35.         Instantiate (Grass, new Vector3 (X, RandY, Z), Quaternion.identity);
    36.     }
    37.    
    38.     void GenerateBedrock()
    39.     {
    40.         Instantiate (Bedrock, new Vector3 (X, RandY, Z), Quaternion.identity);
    41.     }
    42.  
    43.     void Update ()
    44.     {
    45.         Rand = Random.Range (-1, 2);
    46.         LastY = Last + Rand;
    47.         print (LastY);
    48.     }
    49.    
    50.     void GenerateChunk()
    51.     {
    52.         for (Z = Z; Z <= 16; Z++)
    53.         {
    54.             for (X = 0; X <= 16; X++)
    55.             {
    56.                 GenerateColumn();
    57.             }
    58.         }
    59.     }
    60.  
    61.     void GenerateColumn()
    62.     {
    63.         BlockNumber = 0;
    64.  
    65.             for (RandY = LastY + Y; RandY >= -50; RandY--)
    66.             {
    67.                 if(BlockNumber < 4)
    68.                 {
    69.                     GenerateGrass();
    70.                 }
    71.                 else if(RandY == -50)
    72.                 {
    73.                     GenerateBedrock();
    74.                 }
    75.                 else
    76.                 {
    77.                     GenerateStone();
    78.                 }
    79.  
    80.                 BlockNumber++;
    81.  
    82.             }
    83.     }  
    84. }
    85.  
    I want it bt be possible for LastY to be more than 1 or less than -1;
     
  2. Ncon123

    Ncon123

    Joined:
    May 6, 2015
    Posts:
    25
    Also any tip and idea on how to create minecraft like generation?