Please help this is a school project due tomorrow I’m trying to make a bomb “pool” in a flappy bird like game so the bombs spawn in different spots you know.
I get the error: Cannot implicitly convert type UnityEngine.GameObject[ ]' to
UnityEngine.GameObject’
Heres my Script:
using UnityEngine;
using System.Collections;
public class ColumnPool : MonoBehaviour
{
public GameObject Columns; //The column game object.
public int ColumnPoolSize = 5; //How many columns to keep on standby.
public float spawnRate = 3f; //How quickly columns spawn.
public float ColumnMin = -1f; //Minimum y value of the column position.
public float ColumnMax = 3.5f; //Maximum y value of the column position.
private GameObject[] Column; //Collection of pooled columns.
private int currentColumn = 0; //Index of the current column in the collection.
private Vector2 objectPoolPosition = new Vector2 (-15,-25); //A holding position for our unused columns offscreen.
private float spawnXPosition = 10f;
private float timeSinceLastSpawned;
void Start()
{
timeSinceLastSpawned = 0f;
//Initialize the columns collection.
columns = new GameObject[columnPoolSize];
//Loop through the collection...
for(int i = 0; i < columnPoolSize; i++)
{
//...and create the individual columns.
columns[i] = (GameObject)Instantiate(Columns, objectPoolPosition, Quaternion.identity);
}
}
//This spawns columns as long as the game is not over.
void Update()
{
timeSinceLastSpawned += Time.deltaTime;
if (GameControl.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
{
timeSinceLastSpawned = 0f;
//Set a random y position for the column
float spawnYPosition = Random.Range(columnMin, columnMax);
//...then set the current column to that position.
columns[currentColumn].transform.position = new Vector2(spawnXPosition, spawnYPosition);
//Increase the value of currentColumn. If the new size is too big, set it back to zero
currentColumn ++;
if (currentColumn >= columnPoolSize)
{
currentColumn = 0;
}
}
}
}