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 GenerateCore : MonoBehaviour
- {
- public int WorldSize_X;
- public int WorldSize_Z;
- public float PerlinAmplitude = 10f;
- public float PerlinFrequency = 10f;
- public GameObject Block_Top;
- public GameObject Block;
- public GameObject Block_Bottom;
- public float TopBegin = 0.7f;
- public float MiddleBegin = 0.3f;
- // Start is called before the first frame update
- void Start() //TODO: Move to own function.
- {
- for (int x = 0; x < WorldSize_X; x++)
- {
- for (int z = 0; z < WorldSize_Z; z++)
- {
- float y1 = Mathf.PerlinNoise(x / PerlinFrequency, z / PerlinFrequency) * PerlinAmplitude;
- float y2 = Mathf.PerlinNoise(x / Random.Range(PerlinFrequency * 0.9f, PerlinFrequency * 1.1f), z / Random.Range(PerlinFrequency * 0.9f, PerlinFrequency * 1.1f)) * Random.Range(PerlinAmplitude * 0.9f, PerlinAmplitude * 1.1f); // more "realistic" terrain
- float y3 = Mathf.PerlinNoise(x / Random.Range(PerlinFrequency * 0.8f, PerlinFrequency * 0.9f), z / Random.Range(PerlinFrequency * 1.1f, PerlinFrequency * 1.2f)) * Random.Range(PerlinAmplitude * 0.95f, PerlinAmplitude * 1.05f); // more "realistic" terrain
- float y4 = Mathf.PerlinNoise(x / Random.Range(PerlinFrequency * 1.2f, PerlinFrequency * 1.35f), z / Random.Range(PerlinFrequency * 0.85f, PerlinFrequency * 1.0f)) * Random.Range(PerlinAmplitude * 1.1f, PerlinAmplitude * 1.2f); // more "realistic" terrain
- float y = (y1 + y2 + y3 + y4) / 2;
- GameObject GObject = new GameObject();
- if (y / PerlinAmplitude >= Random.Range(TopBegin * 0.90f, TopBegin * 1.10f)) //Snow on mountains
- {
- GObject = GameObject.Instantiate(Block_Top);
- }
- else if (y / PerlinAmplitude >= Random.Range(MiddleBegin * 0.90f, MiddleBegin * 1.10f) && y / PerlinAmplitude < Random.Range(TopBegin * 0.90f, TopBegin * 1.10f))
- {
- GObject = GameObject.Instantiate(Block);
- }
- else
- {
- GObject = GameObject.Instantiate(Block_Bottom);
- }
- GObject.transform.position = new Vector3(x, y, z); // very temporary.
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement