How to make random alien fire and not all of them at once..

Hi am making Space invaders following Derick Banas tutorial, however, how do i make a random alien shoot instead of all of them?
this is what i have but itdoesnt work, it take obj and it fires the count of i as aliens.
private void FixedUpdate()
{
if (Time.time > baseFireWaitTime)
{
objs = GameObject.FindGameObjectsWithTag(“Alien”);
int i = Random.Range(1,objs.Length);

//baseFireWaitTime = baseFireWaitTime + Random.Range(minFireRateTime, maxFireRateTime);
Instantiate(alienBullet, objs*.transform.position,Quaternion.identity);*
print(objs*);*
baseFireWaitTime += 5;
}
}

Ya, well that’s the issue. If this script is on all aliens, each bullet will spawn at the same time since this just waits 5 seconds between shots From the beginning of the game I assume. And some of the bullets will be surely spawning on top of each other with the way things are now. If you want to have the bullets instantiate on each alien at random intervals then that could work, but instead of using Random.Range on to decide your instantiation point, you would use it define the moment to instantiate and instantiate each bullet at Gun position of the alien ship it’s attached to.


Another option, like you mentioned in your previous comment is to manage all bullets from one script. A bullet factory/object pool script would be my choice and reuse the bullets instead of destroying and instantiating them. Give each alien ship a random timer, and when the timer is up, assign the first available bullet to that ships gun position.

First, assign an integer to every alien as an ID. You can have an empty GameObject that chooses a random number for the alien every x frames that you want. After that, each alien will access that variable and check if it is their ID and if it is then the alien will fire.

Hi I tried finding a solution and decide to instantiate my prefabs as an array and call a specific array to test it out to see if only that one alien fires but they all still fire? Do yall know what I’m doing wrong?
@highpockets @Saiansh2525

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestAlien : MonoBehaviour
{
public GameObject alienBullet;
public GameObject Invader1;
private Rigidbody2D rigibod;
public float minFireRateTime;
public float maxFireRateTime;
public float baseFireWaitTime;

private void Start()
{
for (int i = 0; i < Invader1.Length; i++)
{
rigibod = new Rigidbody2D[Invader1.Length];
rigibod = Invader1*.GetComponent();*
rigibod_.velocity = new Vector2(1, 0) * 10;
}_

}
public void CreateInvaders()
{

for (int i = 0; i < Invader1.Length; i++)
{
Instantiate(Invader1_, new Vector2(-i * 5 - (3), -5), Quaternion.identity);_

}
}
// Update is called once per frame
public void FixedUpdate()
{
if (Time.time > baseFireWaitTime)
{

Instantiate(alienBullet,Invader1[1].transform.position, Quaternion.identity);
baseFireWaitTime += 5;

}

}
}