I am trying to make a 2D flappy bird game on Unity 2021.3.3f1, Ive figured out how to make the bird move in and made player move script for that, now I am trying to do a pillar spawning script for the pipes and so far I have this, I am trying to use my List pillarPrefabs and I feel like the error is coming from that as the error is this:
Assets\Scripts\PillarSpawner.cs(39,9): error CS0311: The type 'System.Collections.Generic.List<UnityEngine.GameObject>' cannot be used as type parameter 'T' in the generic type or method 'Object.Instantiate(T, Vector3, Quaternion, Transform)'. There is no implicit reference conversion from 'System.Collections.Generic.List<UnityEngine.GameObject>' to 'UnityEngine.Object'.
Here is my CODE for the pillar spawn script so far, any help would be appreciated, thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PillarSpawner : MonoBehaviour
{
[SerializeField]
private List<GameObject> pillarPrefabs; //A list of pillar object templates
[SerializeField]
private float spawnMinTime; //The minimum amount of time to wait before spawning a pillar
[SerializeField]
private float spawnMaxTime; //The maximum amount of time to wait before spawning a pillar
private float nextSpawnTime; //The next time to spawn a pillar
// Start is called before the first frame update
void Start()
{
nextSpawnTime += Time.deltaTime;
if(nextSpawnTime > spawnMinTime)
{
SpawnObject();
nextSpawnTime = 0f;
}
//Initalize when you will spawn the first pillar here.
}
// Update is called once per frame
void Update()
{
//Here we will want to check if it's time to spawn another pillar.
float offsetY = UnityEngine.Random.Range(-spawnMaxTime, spawnMaxTime);
Vector3 pos = new Vector3(this.transform.posiution.x, this.transform.position.y + offsetY);
Instantiate(pillarPrefabs, pos, Quaternion.identity, this.transform);
//To spawn a pillar:
//Randomly select a pillar template from the list
//Use Instantiate to create an instance of that template in the game world.
//Select the next time to spawn a pillar
}
}