public bool IsThereEnemyScanned()
{
if (!Physics.SphereCast(transform.position, _scanRange, Vector3.up, out RaycastHit hit, 0, _targetLayer))
{
Debug.Log("현재 조준시스템에 포착된 적이 없습니다.");
return false;
}
_targetingEnemy = hit.transform.GetComponent<Test_Enemy>().transform;
return true;
}
C#
복사
Sphere Cast는 안 되고…
public bool IsThereEnemyScanned()
{
RaycastHit[] hits = Physics.SphereCastAll(transform.position, _scanRange, Vector3.up, 0, _targetLayer);
if (hits.Length == 0)
{
Debug.Log("현재 조준시스템에 포착된 적이 없습니다.");
return false;
}
_targetingEnemy = hits[0].transform.GetComponent<Test_Enemy>().transform;
return true;
}
C#
복사
SphereCastAll은 됨…
해결
SphereCast는 내부를 검사하지 않고 Sphere 테두리에 닿은 부분만 검출한다.
radius만큼 플레이어의 뒤쪽에서 SphereCast를 하거나
아예 몬스터들을 관리하는 리스트에서 하나씩 검사하면 될듯.
당장 해결할 수 있는 방법은 SphereCast origin 조절이니 이 방법으로 하고 나중에 Manager를 통해 해보도록 하자.(비교해서 더 좋은걸 쓰자)