So far, this has been my most difficult task yet, and I have just managed to fix it up.
The first code I made was just to make sure the base idea of the code would work. I originally made the code so that it would change the colour of the enemy sprite, just to check that the cone of vision worked.
This worked properly, and caused the enemy to change from a cyan colour, to a dark blue colour when it saw the player…
I then edited the code from colour change, to an ‘if’ statement using booleans where firing is toggled off and on.
This was where I really slipped up, because I was confused about what I needed to do next. It wasn’t as obvious a fix as my last goof, but this time my mistake was that I didn’t know to literally drag the behaviour scripts from the enemy’s inspector view into the respective slots. And once I had figured that out, it still wasn’t working, but it was because for some reason, the ‘projectile’ code turned itself off in the projectile prefab.
Once I turned that on, it worked like a dream.
At this current point I am over the moon with my game. I have included all of the code I need so far, and all of it is running super smoothly! The only things I would change about my game from this point on are purely cosmetic things, maybe make a newer map or jazz up the collectable item, maybe even add a new level, because I already have all of the necessary code. I think the most likely change I will make is the cosmetic changes, a new map is probably the most outstanding thing I’d change because it doesn’t look great.