나는 잠시 동안 인터넷 검색을하고 있었지만, 무엇을 찾아야할지 모르기 때문에 좋은 사람들에게 도움을 요청할 것입니다.Unity : 절차 적으로 생성 된지도에서 적을 산란하기
첫 번째 게임의 절차 단계 제작자로 일하고 있습니다. 코드의 일부는 여기 튜토리얼에서 영감을 얻었지만 최대한 많은 노력을 기울였습니다. 어쨌든, 여기에 내가 지옥으로 아마 추한 인 도움이 필요 코드, 그리고 난 후 도움이 필요 무엇을 설명 할 것이다 :
Vector3 RandomPosition()
{
int randomIndex = Random.Range (0, gridPositions.Count);
Vector3 randomPosition = gridPositions [randomIndex];
gridPositions.RemoveAt (randomIndex);
return randomPosition;
}
void LayoutObjectAtRandom (GameObject[] tileArray, int minimum, int maximum)
{
int objectCount = Random.Range (minimum, maximum);
for (int i = 0; i < objectCount; i++)
{
Vector3 randomPosition = RandomPosition();
GameObject tileChoice = tileArray [Random.Range (0, tileArray.Length)];
Instantiate (tileChoice, randomPosition, Quaternion.identity);
}
}
void spawnTomcats() // Figure out a way to use the RandomPosition to exclude used tiles in enemySpawn
{
int enemyCount = (int)Mathf.Log (level, 2f);
for (int i = 0; i < enemyCount; i++)
{
Vector3 enemySpawn = new Vector3 (columns + (Random.Range (0, 5)), rows - (Random.Range (7, 14)), 0f);
GameObject tileChoice = enemyTiles [Random.Range (0, enemyTiles.Length)];
Instantiate (tileChoice, enemySpawn, Quaternion.identity);
}
public void SceneSetup (int level)
{
BoardSetup();
InitialiseList();
spawnTomcats();
LayoutObjectAtRandom (impassableObjects, impassableCount.minimum, impassableCount.maximum);
Instantiate (heatCat, new Vector3 (columns - 8, rows - (Random.Range(7, 14)), 0f), Quaternion.identity);
}
}
그럼, 내가 필요로하는 것은 선택할 수있는 "Vector3 enemySpawn"입니다 지정된 파라미터 내의 타일. 다만, SceneSetup 함수로 impassableObject를 인스턴스화하는 것으로 아직 사용되어 있지 않다. 모든 것은 산란 부분에서 작동하지만 내 "톰캣 (Tomcats)"은 때로는 공격 할 수없는 대상 위에 산란합니다. RandomPosition() 메서드를 여러 가지 방법으로 통합하려고했지만 실제로 성공하지 못했습니다.
내 변수와 같은 추가 정보가 필요하면 알려주십시오. 나는 아직도 초보자로서 얼마나 필요한지 잘 모르겠다.
모든 조언을 주시면 감사하겠습니다.
조엘 크로스비.
내 대답이 도움이된다면 받아 들일 수있는 것으로 표시하는 것을 잊지 말고, 알려 주시면 자세히 설명 드리겠습니다. –
나는 잊지 않았으며 잊지 않을 것입니다. 제대로 작동하도록하고 싶기 때문에 동시에 내 솔루션을 게시 할 수 있습니다. 당신의 게시물은 나 자신이 해결할 수있는 충분한 관점을주었습니다. 그래서 그것에 대해 감사드립니다. –