Enemy isnt shooting unless

I’ve followed the code Rick has given on “make enemy shoot” even to the point where I grabbed his whole code and pasted it in. But once I clicked play the enemies were not shooting. After trying to understand what was going wrong I decided to change the shotCounter -= Time.deltaTime; if (shotCounter <= 0f) to Time.deltaTime; if (shotCounter <= 1f) and the enemies now shoot. I can only assume time.deltatime isnt counting down to 0 or below or something along those lines. Is there a way I can fix this or should I simply leave the new number at 1? Or am I just insane…

Hi UnstableAlpaca,

Welcome to our community! :slight_smile:

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Are there any error messages in your console?

And have you checked the Hierarchy? Maybe the enemy is shooting but the projectiles get rendered behind the background. Is the z-position of the background set to 10, the z-position of the camera to -10 and the z-position of the other game objects to 0?

It turns out that when I set the min and max shots to Serialized Field unity decided to give them a min and max of 3 and 2. Also the random number was not effecting it, so every shot was going off the max not a random between max and min. It took my ship 3 seconds to spawn and leave so they never had time to shoot since it would take 3 seconds for the code to fire the round by that time they were destroyed. Even if I change the numbers to 0.2 and 3 in the unity inspector the random number still has no effect so I removed both min and max from Serialize Field and now it is working fine.

The bullets did fire normally when I changed the number so it was all fine but the shots were always setting to 3 seconds max on debug not a random number. I did manage to figure it out after realizing that changing the min/max numbers in the code did nothing leading me to Serialize Field in unity. I managed to post the fix as a reply, but thank you for the quick response it eventually lead me to the answer.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms