카테고리 없음

팀 프로젝트

rxo2 2025. 4. 7. 21:08
public int stageFieldWidth = 20;   // 스테이지 가로 타일 수 (sw)
public float tileSize = 0.5f;      // 하나의 타일 크기 (월드 좌표 기준)
void CalculateStageSize()
{
    int tileWidth = stageFieldWidth + 4;  // 좌우 경계 영역 포함
    int tileHeight = 18;                  // 상하 경계 + 필드 등 전체 타일 수

    totalWidthWorld = tileWidth * tileSize;
    totalHeightWorld = tileHeight * tileSize;
}
void SpawnMonsterTopArea()
{
    int monsterSpawnAreaWidth = stageFieldWidth;  // 가로 타일 수 (20)
    int monsterSpawnAreaHeight = 2;               // 상단 스폰 가능 범위 (2타일 높이)
    int ySpawn = 17; // 전체 36타일 중 가장 위쪽 타일 인덱스 (0~17)

    float randX = Random.Range(0, monsterSpawnAreaWidth);
    float randY = Random.Range(ySpawn - monsterSpawnAreaHeight, ySpawn);

    Vector3 spawnPosition = new Vector3(
        randX * tileSize + tileSize / 2f, // 타일 중심 위치 보정
        0f,
        randY * tileSize + tileSize / 2f
    );

    Instantiate(monsterPrefab, spawnPosition, Quaternion.identity);
}

 

 

-   randX * tileSize: 타일의 왼쪽 아래 모서리 위치

-   + tileSize / 2f: 타일 중앙 보정

-   Quaternion.identity: 회전 없이 그대로 생성

-   Debug.Log: 어떤 타일에서 생성됐는지 확인용 출력