Charlie's Documentation - kreetin7/SuperHotClone2018 GitHub Wiki

****BEFORE YOU READ THIS: I SUBMITED ALL OF MY DEVLOGS SO PLEASE LET ME HAVE PARTIAL CREDIT :heart: ****

This is a link to the spawn projectiles script that I wrote using the help of a tutorial and then later edited because the tutorial was not efficient and related to exactly what I was trying to do: https://github.com/kreetin7/SuperHotClone2018/blob/master/Assets/Charlie's%20Scripts/SpawnProjectiles.cs

If you want the reference tutorial it is found here: https://www.youtube.com/watch?v=xenW67bXTgM

This is a link to an image of my superhot bullet that I made: https://imgur.com/a/Nh5YcFa (its very primitive but I assure you there were multiple iterations.)

I am going to speak about my spawn projectile script that I wrote and spoke about above (https://github.com/kreetin7/SuperHotClone2018/blob/master/Assets/Charlie’s%20Scripts/SpawnProjectiles.cs) I will start off by saying that the commenting on this code is absolutely atrocious and I am very well aware of it, it is something I put off almost always when in reality I shouldn’t because it is a really bad habit that I need to break. Moving on to the actual code, we will begin with the variables. The only ones being used in the final version of the game are firePoint, bullet, isHoldingGun, bulletsInGun, timeToFire and audioScript. The reference to the rotateToMouse script was only for testing purposes. The GameObject firePoint is a public variable that is a child to the player within the game scene, and is responsible for where the bullets “come out of”. Bullet is a GameObject that is the prefab which is instantiated when firing the gun. IsHoldingGun is a simple Boolean that is responsible for tracking whether the player is holding the gun. BulletsInGun is a integer responsible for keeping track of how many bullets are left in the gun. TimeToFire is a float that is used a timer to determine how long a player must wait until they can fire another bullet. And lastly the AudioScript is a reference to the audioscript, which is responsible for making sounds.

There are three functions within this script: setGunBoolTrue, setGunBoolFalse, and SpawnVFX. The setGunBool functions do exactly what you would guess and allow other scripts to be capable of setting the isHoldingGun Boolean. SpawnVFX is the function responsible for creating and “Firing” the bullet. Yes I am very aware that SpawnVFX is dated nomenclature left as residue from the tutorial. This function creates a new game object titled newBullet which is initialized within the function itself. The function checks to see if a firePoint has been set and exists, and if it does, it initializes newBullet by instantiating the bullet prefab from the firePoint with the rotation of the camera. It then checks to see if the rotateToMouse script exists, which it doesn’t in the final versions, so this section is ignored.

Finally we look at the update function. The update function checks to see if the player is holding the gun by using isHoldingGun, then checks to see if there are bullets in the gun using bulletsInGun (yes I know it’s a bad idea to have this be set on this script because it means that the actual gun itself isn’t responsible for knowing how much ammo it has, thus there couldn’t be multiple guns with varying ammo unless you manually increase this integer which is a really sloppy way to do things, but we only had one gun so it worked) If both of these are true, then update checks to see if the player presses their mouse button down AND if Time.time is greater than or equal to timeToFire then set timeToFire equal to time.time plus 1 divided by a variable on the bulletprefab which is set to 3. It does this to prevent rapid fire of bullets and so you can only fire within certain increments of time. Then we call SpawnVFX which creates our bullet, we then play the bullet sound effect, and finally decrease the number of bulletsInGun by 1, and that is a really in depth analysis of how the spawn projectile script works.