I want the bullets to fire /instantiate at random times from .2 seconds up to 1.3 seconds each time
so 1 bullet at random times
so here is c script; below
public class BulletFireScript : MonoBehaviour {
public float fireTime = .05f;
public GameObject bullet;
public int pooledAmount = 20;
List< GameObject> bullets;
void Start () {
Debug.logger.logEnabled = false;
bullets = new List ();
for (int i = 0; i < pooledAmount; i++) {
GameObject obj = (GameObject)Instantiate (bullet);
obj.SetActive (false);
bullets.Add (obj);
}
InvokeRepeating ("Fire", fireTime, fireTime);
}
void Fire()
{
for (int i = 0; i < bullets.Count; i++)
{
if (!bullets [i].activeInHierarchy)
{
bullets [i].transform.position = transform.position;
bullets [i].transform.rotation = transform.rotation;
bullets [i].SetActive (true);
break;
}
}
}
}
↧