hi guys I’m trying to instantiate a bullet using Object Pooling, I am new to programming games and I don’t know why no bullet is being instantiated if I press fire2 although there are pre instantiated bullet clones in my Game Controller…thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bulletspawn : MonoBehaviour {
public GameObject bullet;
public List bulletspawner; //
public List activePlayerTurrets;
public float scatterShotTurretReloadTime = 2.0f;
void Start()
{
}
void FixedUpdate()
{
bool shoot = Input.GetButtonDown (“Fire2”);
foreach(GameObject turret in activePlayerTurrets) {
GameObject bullet = objectpooler.SharedInstance.GetPooledObject ();
if (bullet != null) {
bullet.transform.position = turret.transform.position;
bullet.transform.rotation = turret.transform.rotation;
bullet.SetActive (true);
}
}
}
IEnumerator Activatebulletspawner ()
{
while (true) {
foreach (GameObject turret in bulletspawner) {
GameObject bullet = objectpooler.SharedInstance.GetPooledObject ();
if (bullet != null) {
bullet.transform.position = turret.transform.position;
bullet.transform.rotation = turret.transform.rotation;
bullet.SetActive (true);
}
}
yield return new WaitForSeconds (scatterShotTurretReloadTime);
{
}
}
}
}