Advertisement
Cosmo224

test

Mar 14th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GenerateCore : MonoBehaviour
  6. {
  7. public int WorldSize_X;
  8. public int WorldSize_Z;
  9.  
  10. public float PerlinAmplitude = 10f;
  11. public float PerlinFrequency = 10f;
  12.  
  13. public GameObject Block_Top;
  14. public GameObject Block;
  15. public GameObject Block_Bottom;
  16.  
  17. public float TopBegin = 0.7f;
  18. public float MiddleBegin = 0.3f;
  19.  
  20. // Start is called before the first frame update
  21. void Start() //TODO: Move to own function.
  22. {
  23. for (int x = 0; x < WorldSize_X; x++)
  24. {
  25. for (int z = 0; z < WorldSize_Z; z++)
  26. {
  27.  
  28. float y1 = Mathf.PerlinNoise(x / PerlinFrequency, z / PerlinFrequency) * PerlinAmplitude;
  29. 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
  30. 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
  31. 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
  32.  
  33. float y = (y1 + y2 + y3 + y4) / 2;
  34.  
  35. GameObject GObject = new GameObject();
  36.  
  37. if (y / PerlinAmplitude >= Random.Range(TopBegin * 0.90f, TopBegin * 1.10f)) //Snow on mountains
  38. {
  39. GObject = GameObject.Instantiate(Block_Top);
  40. }
  41. else if (y / PerlinAmplitude >= Random.Range(MiddleBegin * 0.90f, MiddleBegin * 1.10f) && y / PerlinAmplitude < Random.Range(TopBegin * 0.90f, TopBegin * 1.10f))
  42. {
  43. GObject = GameObject.Instantiate(Block);
  44. }
  45. else
  46. {
  47. GObject = GameObject.Instantiate(Block_Bottom);
  48. }
  49.  
  50. GObject.transform.position = new Vector3(x, y, z); // very temporary.
  51. }
  52. }
  53. }
  54.  
  55. // Update is called once per frame
  56. void Update()
  57. {
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement