private void PreCreateMoles() { /* To ensure all moles are on the screen are visible I create them from the bottom up depending on the grid * So I first calculate the bottom middle position as a starting point */ Vector3 botMid = new Vector3((_spawnLimitBotLeft.x + _spawnLimitTopRight.x) / 2, _spawnLimitBotLeft.y, _spawnLimitBotLeft.z); /* Then I calculate the maximum size of the squares to fill the field */ float screenWorldWidth = _spawnLimitTopRight.x - _spawnLimitBotLeft.x; float screenWorldHeight = _spawnLimitTopRight.z - _spawnLimitBotLeft.z; float possibleMoleWidth = screenWorldWidth / _gridSize.x; float possibleMoleHeight = screenWorldHeight / _gridSize.y; float moleSize = possibleMoleWidth < possibleMoleHeight ? possibleMoleWidth : possibleMoleHeight; /* Using these values I can precreate objects so I dont have to recalculate this at runtime */ for (int x = 0; x < _gridSize.x; x++) { for (int y = 0; y < _gridSize.y; y++) { Vector3 position = new Vector3(botMid.x - moleSize * _gridSize.x / 2 + moleSize / 2 + x * moleSize, _spawnLimitBotLeft.y, _spawnLimitBotLeft.z + moleSize / 2 + y * moleSize); MoleEntity newMole = Instantiate(_molePrefab, position, Quaternion.identity, transform); newMole.Setup(moleSize); _inactiveMoles.Add(newMole); } } }