I have built a decent code using enemy prefab using but it seems that when i created a spawn script and cloned it, Only one enemy will shoot. Even though all the others are within range and following my “Player”. If any “Enemy” is within range of the “Player” only one will actually use the firing point connected to one “Enemy”. i think i narrowed it down to my “EnemyGun” script. So my question is if I clone the others using a spawn code how can i differentiate the other clones in my code to use their own firingPoint.this is attached to my “EnemyGun” script.
{
[SerializeField]
Transform firingPoint;
[SerializeField]
GameObject projectilePrefab;
[SerializeField]
float firingSpeed;
public static EnemyGun Instance;
private float lastTimeShot = 0;
public AudioSource audioSource;
public AudioClip GunSound;
void Start()
{
audioSource = GetComponent<AudioSource>(); //starting sound
}
void Awake()
{
Instance = GetComponent<EnemyGun>();
}
public void Shoot()
{
if (lastTimeShot + firingSpeed <= Time.time)
{
lastTimeShot = Time.time;
Instantiate(projectilePrefab, firingPoint.position, firingPoint.rotation);
audioSource.PlayOneShot(GunSound, 0.8f); //activate sound
}
}
}