Created
February 20, 2022 02:55
-
-
Save dntf-studio/f18e84288533282ac823e8efa7dd924a to your computer and use it in GitHub Desktop.
Unityでパーリンノイズを使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PerlinNoise : MonoBehaviour | |
{ | |
public GameObject player; | |
public GameObject parent; | |
public GameObject grass; | |
public GameObject stone; | |
[SerializeField] | |
int fieldSize = 50; | |
[SerializeField, Range(0.03f,0.4f)] | |
float scaler = 0.15f; | |
//private float stoneChunk = 3; | |
// Start is called before the first frame update | |
private void Awake() | |
{ | |
Application.targetFrameRate = 30; | |
} | |
void Start() | |
{ | |
Vector3 p_position = player.transform.localPosition; | |
setBlocks(p_position,fieldSize); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
void setBlocks(Vector3 p,int size) | |
{ | |
int s = size; | |
for(var i = 0; i < s; i++) | |
{ | |
for(var j = 0; j < s; j++) | |
{ | |
//パーリンノイズ | |
var noise = Mathf.PerlinNoise(i*scaler,j*scaler); | |
var y_noise = (int)(noise * 10f); | |
//Debug.Log((int)(noise*10f)); | |
Instantiate(grass, new Vector3(p.x - i, y_noise, p.z + j), Quaternion.identity); | |
for(int y = y_noise-1; y >= 2; y--) | |
{ | |
Instantiate(stone, new Vector3(p.x - i, y, p.z + j), Quaternion.identity); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment