Today I Learned :
NavMesh.SamplePosition
주어진 포지션에서 가장 가까운 NavMesh 위의 유효한 위치를 찾아주는 역할
파라미터는 (기준위치, 결과 저장할 NavMeshHit 변수, 최대거리(반지름), 탐색할 NavMesh 레이어)
public void RespawnAnimal(Vector3 centerPos)
{
int createNum = Random.Range(1, 4);
Debug.LogWarning(createNum);
for (int i = 0; i < createNum; i++)
{
GameObject animal = animals[Random.Range(0, animals.Length)].prefab;
// 랜덤 위치에서 가장 가까운 Navmesh위 유효 위치를 탐색
Vector3 randomPosition = Random.onUnitSphere * spawnRadius + centerPos;
randomPosition.y = 100f;
Ray ray = new Ray(randomPosition, Vector3.down);
RaycastHit hit;
NavMeshHit navhit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (NavMesh.SamplePosition(hit.point, out navhit, spawnRadius, NavMesh.AllAreas))
{
Instantiate(animal, navhit.position, Quaternion.identity);
}
}
// 위에서 레이쏘는 방식
//Vector3 randomPosition = Random.onUnitSphere * spawnRadius + centerPos;
//randomPosition.y = 100f;
//Ray ray = new Ray(randomPosition, Vector3.down);
//RaycastHit hit;
//if (Physics.Raycast(ray, out hit, Mathf.Infinity))
//{
// randomPosition.y = hit.point.y;
// Debug.LogWarning("CreateAnimal " + randomPosition);
// Instantiate(animal, randomPosition, Quaternion.identity);
//}
//else
//{
// Debug.LogWarning("Not Hit" + randomPosition);
//}
}
}
Lighting 이슈
개발중인 프로젝트를 유니티상에서 플레이하면 Scene 전환시에 화면이 어두워지는 문제가 발생
게임을 빌드해서 실행하는 경우에는 문제가 발생하지 않는다고 한다.
해결방법
씬별로 라이팅을 생성해주면 문제가 해결된다.
- Window > Rendering > Lighting
- Auto Generate 가 체크된 경우 해제
- Generate Lighting 실행
생성되는데 시간이 꽤 많이 걸린다.
생성 후에는 씬과 동일한 경로에 씬 이름으로 된 폴더와 세팅파일이 생기며 이후 정상적으로 작동된다
'TIL' 카테고리의 다른 글
20240220 TIL (1) | 2024.02.20 |
---|---|
20240219 TIL (0) | 2024.02.19 |
20240214 TIL (1) | 2024.02.15 |
20240213 TIL (0) | 2024.02.13 |
20240207 TIL (0) | 2024.02.07 |