私はUnity3D、C#の単純な村のビルドゲームに取り組んでいます。私はそれを作って、ゲームはプレハブのクローンである50x50ブロックの地面を生成するでしょう。どのようにして芝生の塊(各別個のゲームオブジェクト)を脚本(別のタグを付けること)によって森に分類するのですか?ランダムに子供のgameobjectsを選択する方法
現在のスクリプト:
//GameObjects
public GameObject cube;
public GameObject groundParent;
//Integers
public int worldWidthX;
public int worldWidthZ;
public int mapHeight;
//Floats
private float mapSizeX;
private float mapSizeZ;
public void GenerateTerrain()
{
for(int x = 0; x <= this.worldWidthX; x++, x++)
{
for(int z = 0; z <= this.worldWidthZ; z++, z++)
{
float y = /*Mathf.PerlinNoise(x/30, 76) * Mathf.PerlinNoise(z/30, 22) * 40;*/ mapHeight;
GameObject groundChild = Instantiate(this.cube, new Vector3(x, y, z), this.cube.transform.rotation);
groundChild.transform.parent = groundParent.transform;
}
}
forestMaxAmount = (worldWidthX * worldWidthZ)/8;
forestMinAmount = (worldWidthX * worldWidthZ)/25;
forestAmount = Mathf.RoundToInt(Random.Range (forestMinAmount, forestMaxAmount));
Debug.Log (forestAmount);
}
私はこの質問は、より/特定分かりやすくできているどのような方法があれば、私はそうする喜んでいると思います。ご協力いただきありがとうございます。
コードには、乱数を生成しようとしました。 Unityで乱数を生成する方法をGoogleに教えてください。 – Programmer
私はちょうど子供のgameobjectsのこのランダムな量をランダムに選択し、次にそれらに異なるタグを適用することができるだろうと思っています。 –
可能です。質問を編集し、Unityで乱数を生成できることを示します。あなたがそれを行うことができない場合、それをGoogleに。この質問であなたがしていることをやろうとする試みをしたら、繰り返しますが、できない場合は、そのコードを投稿してください。 – Programmer