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! ^^
↧