Hi everyone. I have go a warning but it converted error when game is playing. At the console 1-number line is being pointed. And the information at this line goes to 2-number line us and it goes to 3 but ı have defined everything. I could not understand where is the problem. Besides at game, the error is “NullReferenceException: Object reference not set to an instance of an object” . Thanks ahead.
foreach (SnakeBodyPart snakeBodyPart in snakeBodyPartList)
{
Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition(); [B] 1[/B]
if (gridPosition == snakeBodyPartGridPosition)
{
Debug.Log("death");
}
}
private class SnakeBodyPart
{
private SnakeMovePosition snakeMovePosition; [B]2[/B]
private Transform transform;
public SnakeBodyPart(int bodyIndex)
{
GameObject snakeBodyGameObject = new GameObject("SnakeBody", typeof(SpriteRenderer));
snakeBodyGameObject.GetComponent<SpriteRenderer>().sprite = GameAssets.i.snakeBodySprite;
snakeBodyGameObject.GetComponent<SpriteRenderer>().sortingOrder = -bodyIndex;
transform = snakeBodyGameObject.transform;
}
public void SetSnakeMovePosition(SnakeMovePosition snakeMovePosition)
{
this.snakeMovePosition = snakeMovePosition;
transform.position = new Vector3(snakeMovePosition.GetGridPosition().x, snakeMovePosition.GetGridPosition().y);
}
public Vector2Int GetGridPosition() [B]3[/B]
{
return snakeMovePosition.GetGridPosition();
}
}
private class SnakeMovePosition
{
private Vector2Int gridPosition;
public SnakeMovePosition(Vector2Int gridPosition)
{
this.gridPosition = gridPosition;
}
public Vector2Int GetGridPosition() [B] [/B]
{
return gridPosition;
}
}