• Как сделать генерацию высот ландшафта?

    SheTTtyn
    @SheTTtyn Автор вопроса
    Всё, нашел решение)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class MapGeneric : MonoBehaviour
    {
        public int rangeX;
        public int rangeY;
        public Vector3[,] coord;
        public GameObject[] gameObjects;
        public float heightScale = 10f;
        public float noiseScale = 0.1f;
    
    
        public void Start()
        {
            SetCoord();
            
            instanceObject();
            
            
        }
    
        public void SetCoord()
        {
            coord = new Vector3[rangeX, rangeY];
            for (int x = 0; x < rangeX; x = x + 2)
            {
                for (int y = 0; y < rangeY; y = y + 2)
                {
                    coord[x, y] = new Vector3(x,0,y);
                    Debug.Log(coord[x, y]);
                }
            }
    
           
        }
    
        public void instanceObject()
        {
            for (int x = 0; x < rangeX; x = x + 2)
            {
                for(int y = 0; y < rangeY; y = y + 2)
                {
                    int z;
                    Vector3 position = coord[x, y];
                    RandomIndex(out z);
    
                    float height = CalculateHeight(position.x, position.z);
                    Vector3 blockPosition = new Vector3(position.x, height, position.z);
    
                    Instantiate(gameObjects[z],blockPosition, gameObjects[z].transform.rotation);
                }
            }
        }
    
        public void RandomIndex(out int x)
        {
            x = Random.Range(0, gameObjects.Length);
        }
    
        public float CalculateHeight(float x, float y)
        {
            float noiseValue = Mathf.PerlinNoise(x * noiseScale, y * noiseScale);
            float height = noiseValue * heightScale;
            return height;
        }
    
    
    
    
    
    
    
    
    
    }
    Ответ написан