다음과 같은 코드가 있습니다.내 코드가 true if-condition을 무시하는 이유는 무엇입니까?
private static void checkCodesInPlayerCenter(GameObject player)
{
Vector2 collisionCenter = player.GetCollisionCenter(player.PublicCollisionRectangle);
if (TileMap.GetMapSquareAtPixel(collisionCenter) == null)
{
return;
}
for (int i = 0; i < TileMap.GetMapSquareAtPixel(collisionCenter).Codes.Count; ++i)
때때로 GetMapSquareAtPixel에서 가져 오는 객체가 null 일 수 있습니다. for 루프에서 NullReferenceException을 발생시키지 않으려면 null인지 확인하고 일찍 함수를 끝내면 반환 된 객체가 null 인 경우에도 if 조건을 완전히 무시한 것처럼 보입니다. return 문에 중단 점을 설정했지만 코드가 절대 이동하지 않고 대신 NullReferenceException을 트리거합니다.
어떤 도움을 주시겠습니까?
아마도 'TileMap'이 null입니다. 혹시? 아니면'코드'? 아니면 '선수'? –
null 인 collisionCenter 일 수 있습니까? – darma
메서드 내부의 첫 번째 줄이 호출 될 때 어떤 결과가 나타 났습니까? – saber