Search Unity

Biome for World Generator

Discussion in 'Getting Started' started by PedroMBP, Dec 26, 2018.

  1. PedroMBP

    PedroMBP

    Joined:
    Feb 25, 2017
    Posts:
    21
    Hi, guys, how are you?
    I am making a simple world generator and would like to have a notion of how I can make biomas, the main objective would be to put different textures on the map?
    Anyone have any suggestions?
    thankful!

    Oh yeah, just to emphasize the terrain's shape are in hexagons.

    Thank for all.

    :)

    My Code




    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6.  
    7. public class TerrainBehaviour : MonoBehaviour
    8. {
    9.  
    10.  
    11.     public GameObject[] hexTransform;
    12.     public List<Vector3> createdHex;
    13.  
    14.     public int ammountHex;
    15.     public float offsetSize;
    16.  
    17.     public bool useSeed;
    18.     public bool randomSeed;
    19.     public int seed;
    20.  
    21.     public GameObject worldContent;
    22.  
    23.     public float chanceLeft, changeRight, changeUp, changeDown;
    24.  
    25.     public NavMeshSurface surface;
    26.  
    27.     public void Start()
    28.     {
    29.  
    30.  
    31.         StartCoroutine(GenerateWorld());
    32.  
    33.         if (useSeed == true)
    34.         {
    35.             Random.InitState(seed);
    36.         }
    37.  
    38.         if (useSeed == true && randomSeed == true)
    39.         {
    40.             seed = Random.Range(0, 9999999);
    41.         }
    42.  
    43.     }
    44.  
    45.     IEnumerator GenerateWorld()
    46.     {
    47.  
    48.         for (int i = 0; i < ammountHex; i++)
    49.         {
    50.             int pos = Random.Range(0,5);
    51.             int textureMap = Random.Range(0, hexTransform.Length);
    52.  
    53.             PositionHex(pos);
    54.             SpawnHex(textureMap);
    55.         }
    56.        //surface.BuildNavMesh();
    57.  
    58.         yield return 0;
    59.     }
    60.  
    61.  
    62.  
    63.     private void PositionHex(int pos)
    64.     {
    65.         switch (pos)
    66.         {
    67.             case 0:
    68.                 //Cima
    69.                 transform.position = new Vector3(transform.position.x - (offsetSize / 2), 0, transform.position.z + 0.75f * 50);
    70.                 break;
    71.             case 1:
    72.                 //Esquerda
    73.                 transform.position = new Vector3(transform.position.x + offsetSize, 0, transform.position.z);
    74.                 break;
    75.             case 2:
    76.                 //Direta
    77.                 transform.position = new Vector3(transform.position.x - offsetSize, 0, transform.position.z);
    78.                 break;
    79.  
    80.             case 3:
    81.                 //Baixo
    82.                 transform.position = new Vector3(transform.position.x + (offsetSize / 2), 0, transform.position.z - 0.75f * 50);
    83.                 break;
    84.  
    85.         }
    86.  
    87.     }
    88.  
    89.     void SpawnHex(int pos)
    90.     {
    91.         if (!createdHex.Contains(transform.position))
    92.         {
    93.             GameObject Hex = Instantiate(hexTransform[pos], transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
    94.             createdHex.Add(Hex.transform.position);
    95.             Hex.name = "Hex" + transform.position.x + " / " + transform.position.z;
    96.             Hex.gameObject.transform.SetParent(worldContent.transform);
    97.             //     Hex.transform.SetParent(transform);
    98.         }
    99.         else
    100.         {
    101.             ammountHex++;
    102.         }
    103.  
    104.     }
    105.  
    106.  
    107.     private void Update()
    108.     {
    109.  
    110.  
    111.     }
    112.  
    113. }
     
  2. PedroMBP

    PedroMBP

    Joined:
    Feb 25, 2017
    Posts:
    21
    I apologize, because I did not express myself correctly.
    In my case, my terrain will be a plan, I only need to modify the textures, I have no intention of making mountains or plains.
    I would only really like to change the textures in certain parts, like biomes.
     
  3. Look further in Catlike's tutorial-series. He has what you're looking for. Both biomes and texture manipulation/vertex painting.