// public BoxScript boxScript; // Use this for initialization void Start() { boxes = new GameObject[columns * rows]; if (width > 1) { width = 1; } if (height > 1) { height = 1; } float worldHeight = 2f * Camera.main.orthographicSize; float worldWidth = worldHeight * Camera.main.aspect; // int numberOfBoxes = columns * rows; float boxWidth = (worldWidth * width) / columns; float boxHeight = (worldHeight * height) / rows; // boxWidth = Camera.main.WorldToScreenPoint (boxWidth); // boxHeight = Camera.main.WorldToScreenPoint (boxHeight); lanes = new float[rows]; laneAvailable = new bool[rows]; Vector3 worldBottomLeft = new Vector3(-worldWidth / 2 + boxWidth / 2, -worldHeight / 2 + boxHeight / 2, 0); enemyArea = new Rect(worldBottomLeft.x + left + width * worldWidth, worldBottomLeft.y + bottom, worldWidth - width * worldWidth - left, worldHeight * height); // Vector2 upperLeftCorner = new Vector2 (-screenWidth / 2, -screenHeight / 2); int counter = 0; for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { GameObject box = (GameObject)Instantiate(tilePrefab, worldBottomLeft + new Vector3(i * boxWidth + left, j * boxHeight + bottom, 0), tilePrefab.transform.rotation); boxes[counter] = box; BoxScript boxScript = box.GetComponent <BoxScript>(); boxScript.Generate(counter, boxWidth, boxHeight); counter++; if (i == 0) { lanes[j] = (worldBottomLeft + new Vector3(i * boxWidth + left, j * boxHeight + bottom, 0)).y; laneAvailable[j] = true; } } } }