Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Random enemy fire rate

$
0
0
Hello guys, I'm trying to make a school project (space invader) and I have a itty problem with my alien shooting I want them to shoot at a random rate, I more o less managed to do that I think... Problem is I don't know why, at the beginning of the game they all shoot once, all together. How do I make the random shooting start at the same time the game does? Second, sometime the random make too many bullet pop at once. Is there a way to limit the possible number of alien bullets? script is this using UnityEngine; using System.Collections; public class canonenemy : MonoBehaviour { public GameObject bolt; public Transform Canon; public float fireRatep; public float fireRatem; private float nextFire = 3.0f; // Update is called once per frame void FixedUpdate () { if (Time.time > nextFire) { nextFire = Time.time + Random.Range (fireRatep, fireRatem); Instantiate (bolt, Canon.position, Canon.rotation); } } } Thanks in advance! ^^

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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