-
-
Save todorok1/71a6ec8709c447b3a5012ab706dd24e0 to your computer and use it in GitHub Desktop.
パーリンノイズを重ね合わせてより自然な地形を作ることを目指したサンプル
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
/// <Summary> | |
/// 生成(加算変化)ボタンが押された時のメソッドです。 | |
/// </Summary> | |
public void OnPressedAddPerlinButton() | |
{ | |
isAddMode = true; | |
GenerateMultiPerlinFieldParts(); | |
} | |
/// <Summary> | |
/// 生成(乗算変化)ボタンが押された時のメソッドです。 | |
/// </Summary> | |
public void OnPressedMultiplePerlinButton() | |
{ | |
isAddMode = false; | |
GenerateMultiPerlinFieldParts(); | |
} | |
/// <Summary> | |
/// フィールドを生成するメソッドです。 | |
/// </Summary> | |
void GenerateMultiPerlinFieldParts() | |
{ | |
for (float z = 0f; z < fieldSizeZ; z++) | |
{ | |
for (float x = 0f; x < fieldSizeX; x++) | |
{ | |
// パーリンノイズの座標を指定して値を取得します。 | |
float xValue = (xOrigin + x) * scale; | |
float yValue = (yOrigin + z) * scale; | |
float perlinValue = isAddMode ? GetAddedPerlinNoise(xValue, yValue) : GetMultiplePerlinNoise(xValue, yValue); | |
float height = fieldHeight * perlinValue; | |
// 位置のVector3を作成してオブジェクトをインスタンス化します。 | |
Vector3 pos = new Vector3(x, height, z); | |
InstantiateFieldParts(pos); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment