Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

make enemy fire at randomly times?

$
0
0
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; } } } }

Viewing all articles
Browse latest Browse all 125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>