저는 Unity3D, C#에서 간단한 마을 건물 게임을하고 있습니다. 게임이 프리 프레임의 클론 인 50x50 블록을 생성하도록 만들었습니다. 나는 어떻게 풀의 덩어리 (각 개별 게임 객체)가 스크립트를 통해 (다른 태그를줌으로써) 포리스트로 분류 될 수 있도록 만들까요?임의로 자식 게임 개체를 선택하는 방법
현재 스크립트
//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);
}
계층 : http://prntscr.com/htx5gc
나는이 질문은 더/특정 이해 할 수있는 어떤 방법이 있다면, 나는 그렇게 기쁠 것입니다. 당신의 도움을 주셔서 감사합니다.
코드에 임의의 숫자를 생성하려는 시도가 있습니다. Unity에서 Unity에서 임의의 숫자를 생성하는 방법은 Google뿐입니다. – Programmer
나는 당신이 자식 gameobjects이 무작위로 금액을 무작위로 선택한 다음 다른 태그를 적용 할 수 있을지 궁금 해서요. –
가능합니다. 질문을 편집하고 Unity에서 임의의 숫자를 생성 할 수 있음을 보여줍니다. 그렇게 할 수 없다면 Google에 알려주세요. 일단 당신이이 질문에 당신이 가지고있는 일을하려는 시도를 찾으십시오. 다시 말하지만 그렇게 할 수 없다면 해당 코드를 게시하십시오. – Programmer