├── LeaveGame.cs ├── SceneScript.cs ├── Gunshot.cs ├── NoisyBoi.cs ├── HealthScript.cs ├── NewCameraScript.cs ├── WinCondition.cs ├── PlayerHealth.cs ├── PlayerMovement.cs ├── RigidBodyMove.cs ├── Enemy.cs ├── ChangeWeapon.cs ├── EnemyScript.cs └── ShootScript.cs /LeaveGame.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class LeaveGame : MonoBehaviour 6 | { 7 | 8 | public void doExitGame() 9 | { 10 | Application.Quit(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SceneScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SceneManagement; 5 | 6 | public class SceneScript : MonoBehaviour 7 | { 8 | 9 | public static SceneScript Instance; 10 | 11 | public void Start() 12 | { 13 | Instance = this; 14 | } 15 | 16 | public void LoadScene(string name) 17 | { 18 | SceneManager.LoadScene(name); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Gunshot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Gunshot : MonoBehaviour 6 | { 7 | public static Gunshot Instance; 8 | public AudioSource shootyNoise; 9 | 10 | // Start is called before the first frame update 11 | void Start() 12 | { 13 | Instance = this; 14 | } 15 | 16 | public void shootGun() 17 | { 18 | shootyNoise.Play(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NoisyBoi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class NoisyBoi : MonoBehaviour 6 | { 7 | 8 | public static NoisyBoi Instance; 9 | public AudioSource shootyNoise; 10 | 11 | // Start is called before the first frame update 12 | void Start() 13 | { 14 | Instance = this; 15 | } 16 | 17 | public void MakeNoise() 18 | { 19 | shootyNoise.Play(); 20 | } 21 | } -------------------------------------------------------------------------------- /HealthScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | public class HealthScript : MonoBehaviour 7 | { 8 | 9 | public float health; 10 | 11 | public float maxHealth; 12 | 13 | 14 | // Start is called before the first frame update 15 | void Start() 16 | { 17 | health = maxHealth; 18 | } 19 | 20 | // Update is called once per frame 21 | void Update() 22 | { 23 | 24 | } 25 | 26 | 27 | public void hitMarker(float damage) 28 | { 29 | 30 | health -= damage; 31 | 32 | NoisyBoi.Instance.MakeNoise(); 33 | 34 | if(health <= 0) 35 | { 36 | //Die 37 | Destroy(this.gameObject); 38 | WinCondition.Instance.checkForWin(); 39 | } 40 | 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /NewCameraScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class NewCameraScript : MonoBehaviour 6 | { 7 | 8 | 9 | public float minX = -90f; 10 | public float maxX = 90f; 11 | public float minY = -360f; 12 | public float maxY = 360f; 13 | public float sensivity; 14 | public float xRotation = 0; 15 | public float yRotation = 0; 16 | 17 | public Camera mainCam; 18 | 19 | // Start is called before the first frame update 20 | void Start() 21 | { 22 | Cursor.lockState = CursorLockMode.Locked; 23 | Cursor.visible = false; 24 | 25 | } 26 | 27 | // Update is called once per frame 28 | void Update() 29 | { 30 | yRotation += Input.GetAxis("Mouse X") * sensivity; 31 | xRotation -= Input.GetAxis("Mouse Y") * sensivity; 32 | 33 | xRotation = Mathf.Clamp(xRotation, minX, maxX); 34 | 35 | transform.eulerAngles = new Vector3(0, yRotation, 0); 36 | mainCam.transform.eulerAngles = new Vector3(xRotation, yRotation, 0); 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WinCondition.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SceneManagement; 5 | 6 | public class WinCondition : MonoBehaviour 7 | { 8 | 9 | public static WinCondition Instance; 10 | 11 | public GameObject[] enemies; 12 | 13 | public int totalEnemies; 14 | 15 | public string nextScene; 16 | 17 | // Start is called before the first frame update 18 | void Start() 19 | { 20 | Instance = this; 21 | 22 | enemies = GameObject.FindGameObjectsWithTag("Enemy"); 23 | totalEnemies = 13; 24 | } 25 | 26 | // Update is called once per frame 27 | void Update() 28 | { 29 | if(checkForWin()) 30 | { 31 | Cursor.lockState = CursorLockMode.None; 32 | Cursor.visible = true; 33 | SceneScript.Instance.LoadScene(nextScene); 34 | } 35 | } 36 | 37 | public bool checkForWin() 38 | { 39 | 40 | for(int i = 0; i < totalEnemies; i++) 41 | { 42 | if(enemies[i] != null) 43 | { 44 | return false; 45 | } 46 | } 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /PlayerHealth.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class PlayerHealth : MonoBehaviour 7 | { 8 | 9 | public static PlayerHealth Instance; 10 | 11 | public float health; 12 | public float maxHealth; 13 | public float healthPct; 14 | public float healTimer; 15 | public float timerReset; 16 | 17 | public Transform healthBar; 18 | 19 | // Start is called before the first frame update 20 | void Start() 21 | { 22 | Instance = this; 23 | health = maxHealth; 24 | timerReset = healTimer; 25 | } 26 | 27 | // Update is called once per frame 28 | void Update() 29 | { 30 | Debug.Log(maxHealth + "\t" + health); 31 | HealthBar(); 32 | 33 | if(health < maxHealth) 34 | { 35 | healTimer -= Time.deltaTime; 36 | } 37 | 38 | if(healTimer <= 0) 39 | { 40 | Heal(); 41 | } 42 | 43 | if(health <= 0) 44 | { 45 | 46 | Cursor.lockState = CursorLockMode.None; 47 | Cursor.visible = true; 48 | SceneScript.Instance.LoadScene("Lose"); 49 | 50 | } 51 | } 52 | 53 | 54 | public void PlayerDamage(float damage) 55 | { 56 | health -= damage; 57 | healTimer = timerReset; 58 | } 59 | 60 | public void HealthBar() 61 | { 62 | healthPct = health / maxHealth; 63 | 64 | healthBar.localScale = Vector3.Lerp(healthBar.localScale, new Vector3(healthPct, 1, 1), Time.deltaTime * 8f); 65 | } 66 | 67 | public void Heal() 68 | { 69 | if (health < maxHealth) 70 | { 71 | health++; 72 | } 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /PlayerMovement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PlayerMovement : MonoBehaviour 6 | { 7 | 8 | public static PlayerMovement Instance; 9 | 10 | public float jumpHeight; 11 | public float speed; 12 | public float jumps; 13 | public float xMove; 14 | public float zMove; 15 | public float yMove; 16 | public float gravity; 17 | 18 | public int keys; 19 | 20 | public bool grounded; 21 | 22 | public KeyCode front; 23 | public KeyCode back; 24 | public KeyCode left; 25 | public KeyCode right; 26 | public KeyCode space; 27 | public KeyCode teleportKey; 28 | 29 | public CharacterController pilot; 30 | 31 | public Vector3 movement; 32 | public Vector3 gravMovement; 33 | 34 | // Start is called before the first frame update 35 | void Start() 36 | { 37 | Instance = this; 38 | keys = 0; 39 | grounded = pilot.isGrounded; 40 | } 41 | 42 | // Update is called once per frame 43 | void Update() 44 | { 45 | 46 | 47 | grounded = pilot.isGrounded; 48 | if(grounded && gravMovement.y < 0) 49 | { 50 | gravMovement.y = 0; 51 | } 52 | 53 | //forward and sideways movenemt 54 | xMove = Input.GetAxis("Horizontal"); 55 | zMove = Input.GetAxis("Vertical"); 56 | 57 | movement = transform.right * xMove + transform.forward* zMove; 58 | 59 | //update movenemt 60 | pilot.Move(movement * speed * Time.deltaTime); 61 | 62 | 63 | //jump and fall 64 | if (Input.GetKeyDown(space) && grounded) 65 | { 66 | gravMovement.y += Mathf.Sqrt(jumpHeight * -3.0f * gravity); 67 | } 68 | 69 | gravMovement.y += gravity * Time.deltaTime; 70 | 71 | pilot.Move(gravMovement * Time.deltaTime); 72 | 73 | 74 | //Debug.Log("gravMovement.y: " + gravMovement.y + "\n"); 75 | 76 | 77 | 78 | 79 | 80 | 81 | } 82 | 83 | //hit detection 84 | void OnControllerColliderHit(ControllerColliderHit hit) 85 | { 86 | 87 | } 88 | 89 | 90 | 91 | 92 | } 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /RigidBodyMove.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class RigidBodyMove : MonoBehaviour 6 | { 7 | 8 | public static RigidBodyMove Instance; 9 | 10 | public float xMove, zMove; 11 | public float jumpHeight; 12 | public float moveSpeed; 13 | public float jumpTimer; 14 | public float moveTimer; 15 | public float cast; 16 | public float height; 17 | public float radius; 18 | 19 | public Vector3 p1, p2; 20 | 21 | 22 | public Vector3 movement; 23 | public Vector3 yVelocity; 24 | public Vector3 moveDirection; 25 | 26 | public KeyCode jump; 27 | 28 | public Rigidbody rb; 29 | 30 | public CapsuleCollider cap; 31 | 32 | public bool canJump; 33 | 34 | // Start is called before the first frame update 35 | void Start() 36 | { 37 | Instance = this; 38 | canJump = true; 39 | } 40 | 41 | // Update is called once per frame 42 | void Update() 43 | { 44 | 45 | 46 | if (Input.GetKeyDown(jump) && canJump) 47 | { 48 | rb.velocity = new Vector3(0, jumpHeight, 0); 49 | canJump = false; 50 | } 51 | 52 | 53 | xMove = Input.GetAxis("Horizontal"); 54 | zMove = Input.GetAxis("Vertical"); 55 | 56 | movement = (transform.right * xMove + transform.forward * zMove).normalized; 57 | 58 | } 59 | 60 | void FixedUpdate() 61 | { 62 | if (moveTimer <= 0 && !Caster()) 63 | { 64 | Move(); 65 | } 66 | } 67 | 68 | public void Move() 69 | { 70 | yVelocity = new Vector3(0, rb.velocity.y); 71 | rb.velocity = movement * moveSpeed * Time.deltaTime; 72 | rb.velocity += yVelocity; 73 | } 74 | 75 | private void OnCollisionEnter(Collision col) 76 | { 77 | 78 | if(col.gameObject.tag == "Platform") 79 | { 80 | canJump = true; 81 | } 82 | 83 | } 84 | 85 | 86 | public bool Caster() 87 | { 88 | RaycastHit hit; 89 | Vector3 p1 = transform.position + cap.center + Vector3.up * -cap.height /2.0f; 90 | Vector3 p2 = p1 + Vector3.up * cap.height; 91 | 92 | //return Physics.CapsuleCast(p1, p2, cap.radius, transform.forward, out hit, 1); 93 | return Physics.CapsuleCast(p1, p2, cap.radius, movement, out hit, 1); 94 | 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Enemy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | 6 | 7 | public class Enemy : MonoBehaviour 8 | { 9 | 10 | public float speed; 11 | public float attackRange, sightRange; 12 | 13 | bool withinAttack, withinSight; 14 | 15 | public Vector3 areWeThereYet; 16 | 17 | //patrol variables 18 | public float patrolRange; 19 | bool destinationSet; 20 | public Vector3 destination; 21 | 22 | 23 | //attack variables 24 | public float shootTime; 25 | bool shoot; 26 | 27 | public NavMeshAgent agent; 28 | 29 | public Transform player; 30 | 31 | public LayerMask groundMask, playerMask; 32 | 33 | // Start is called before the first frame update 34 | void Start() 35 | { 36 | player = GameObject.Find("Player").transform; 37 | } 38 | 39 | // Update is called once per frame 40 | void Update() 41 | { 42 | withinSight = Physics.CheckSphere(this.transform.position, sightRange, playerMask); 43 | withinAttack = Physics.CheckSphere(this.transform.position, attackRange, playerMask); 44 | 45 | 46 | if (withinSight && !withinAttack) 47 | { 48 | HotPursuit(); 49 | } 50 | else if (withinAttack) 51 | { 52 | Attack(); 53 | } 54 | else 55 | { 56 | Patrol(); 57 | } 58 | 59 | 60 | 61 | 62 | } 63 | 64 | 65 | public void Patrol() 66 | { 67 | if (!destinationSet) 68 | { 69 | setWalkPoint(); 70 | } 71 | else 72 | { 73 | agent.SetDestination(destination); 74 | } 75 | 76 | areWeThereYet = this.transform.position - destination; 77 | 78 | if (areWeThereYet.magnitude < 2.0f) 79 | { 80 | destinationSet = false; 81 | } 82 | 83 | } 84 | 85 | public void Attack() 86 | { 87 | agent.SetDestination(this.transform.position); 88 | 89 | this.transform.LookAt(player); 90 | 91 | 92 | 93 | } 94 | 95 | public void HotPursuit() 96 | { 97 | agent.SetDestination(player.position); 98 | } 99 | 100 | public void setWalkPoint() 101 | { 102 | 103 | float xPos = Random.Range(-patrolRange, patrolRange); 104 | float zPos = Random.Range(-patrolRange, patrolRange); 105 | 106 | destination = new Vector3(this.transform.position.x + xPos, this.transform.position.y, this.transform.position.z + zPos); 107 | 108 | if (Physics.Raycast(destination, -transform.up, 2f, groundMask)) 109 | { 110 | destinationSet = true; 111 | } 112 | } 113 | 114 | } -------------------------------------------------------------------------------- /ChangeWeapon.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class ChangeWeapon : MonoBehaviour 7 | { 8 | 9 | public int totalGuns; 10 | public int activeGun; 11 | 12 | 13 | public KeyCode switchGuns; 14 | 15 | 16 | public GameObject[] guns; 17 | public GameObject Uzi, Shotgun, Sniper; 18 | 19 | public Image[] crosshairs; 20 | public Image uziCross, shotgunCross, sniperCross; 21 | public Image reloadWhite; 22 | public Image reloadBack; 23 | 24 | public Text[] Txt; 25 | public Text uziText, shotgunText, sniperText; 26 | 27 | // Start is called before the first frame update 28 | void Start() 29 | { 30 | totalGuns = 3; 31 | 32 | activeGun = 0; 33 | guns = new GameObject[totalGuns]; 34 | crosshairs = new Image[totalGuns]; 35 | Txt = new Text[totalGuns]; 36 | 37 | guns[0] = Uzi; 38 | guns[1] = Shotgun; 39 | guns[2] = Sniper; 40 | 41 | guns[0].SetActive(true); 42 | guns[1].SetActive(false); 43 | guns[2].SetActive(false); 44 | 45 | crosshairs[0] = uziCross; 46 | crosshairs[1] = shotgunCross; 47 | crosshairs[2] = sniperCross; 48 | 49 | crosshairs[0].enabled = true; 50 | crosshairs[1].enabled = false; 51 | crosshairs[2].enabled = false; 52 | 53 | Txt[0] = uziText; 54 | Txt[1] = shotgunText; 55 | Txt[2] = sniperText; 56 | 57 | 58 | Txt[0].enabled = true; 59 | Txt[1].enabled = false; 60 | Txt[2].enabled = false; 61 | 62 | 63 | } 64 | 65 | // Update is called once per frame 66 | void Update() 67 | { 68 | if (Input.GetKeyDown(switchGuns)) 69 | { 70 | switchWeapon(); 71 | } 72 | } 73 | 74 | 75 | 76 | public void switchWeapon() 77 | { 78 | 79 | //Switch Guns to the next gun 80 | //Switch Crosshairs to match the gun 81 | //Deactivate other guns and crosshairs 82 | 83 | Debug.Log("Switch Guns"); 84 | 85 | reloadWhite.enabled = false; 86 | reloadBack.enabled = false; 87 | 88 | //Changes ActiveGun to the next weapon and makes sure to stay inside array 89 | activeGun = (activeGun + 1) % totalGuns; 90 | 91 | for (int i = 0; i < totalGuns; i++) 92 | { 93 | if (i == activeGun) 94 | { 95 | //Set the chosen gun to active 96 | guns[i].SetActive(true); 97 | crosshairs[i].enabled = true; 98 | Txt[i].enabled = true; 99 | } 100 | else 101 | { 102 | //set all other guns to inactive 103 | guns[i].SetActive(false); 104 | crosshairs[i].enabled = false; 105 | Txt[i].enabled = false; 106 | } 107 | } 108 | 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /EnemyScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | 6 | 7 | public class EnemyScript : MonoBehaviour 8 | { 9 | 10 | public float speed; 11 | public float attackRange, sightRange; 12 | 13 | bool withinAttack, withinSight; 14 | 15 | public Vector3 areWeThereYet; 16 | 17 | //patrol variables 18 | public float patrolRange; 19 | bool destinationSet; 20 | public Vector3 destination; 21 | 22 | 23 | //attack variables 24 | public float shootTime; 25 | public float timerReset; 26 | public float attackValue; 27 | public float damageValue; 28 | public float rand; 29 | bool shoot; 30 | 31 | public NavMeshAgent agent; 32 | 33 | public Transform player; 34 | 35 | public LayerMask groundMask, playerMask; 36 | 37 | public ParticleSystem muzzleFlash; 38 | 39 | // Start is called before the first frame update 40 | void Start() 41 | { 42 | player = GameObject.Find("Player").transform; 43 | timerReset = shootTime; 44 | } 45 | 46 | // Update is called once per frame 47 | void Update() 48 | { 49 | 50 | withinSight = Physics.CheckSphere(this.transform.position, sightRange, playerMask); 51 | withinAttack = Physics.CheckSphere(this.transform.position, attackRange, playerMask); 52 | 53 | if (withinSight && !withinAttack) 54 | { 55 | HotPursuit(); 56 | } 57 | else if (withinAttack) 58 | { 59 | 60 | shootTime -= Time.deltaTime; 61 | Debug.Log("Attack"); 62 | this.transform.LookAt(player); 63 | 64 | if (shootTime <= 0) 65 | { 66 | rand = Random.Range(0f, attackValue); 67 | if (rand <= 1.0f) 68 | { 69 | Attack(); 70 | } 71 | shootTime = timerReset; 72 | } 73 | } 74 | else 75 | { 76 | Patrol(); 77 | } 78 | 79 | } 80 | 81 | 82 | public void Patrol() 83 | { 84 | if (!destinationSet) 85 | { 86 | setWalkPoint(); 87 | } 88 | else 89 | { 90 | agent.SetDestination(destination); 91 | } 92 | 93 | areWeThereYet = this.transform.position - destination; 94 | 95 | if (areWeThereYet.magnitude < 2.0f) 96 | { 97 | destinationSet = false; 98 | } 99 | 100 | } 101 | 102 | public void Attack() 103 | { 104 | muzzleFlash.Stop(); 105 | 106 | agent.SetDestination(this.transform.position); 107 | 108 | PlayerHealth.Instance.PlayerDamage(damageValue); 109 | Debug.Log("BANG"); 110 | 111 | shootTime = timerReset; 112 | } 113 | 114 | public void HotPursuit() 115 | { 116 | agent.SetDestination(player.position); 117 | 118 | } 119 | 120 | public void setWalkPoint() 121 | { 122 | 123 | float xPos = Random.Range(-patrolRange, patrolRange); 124 | float zPos = Random.Range(-patrolRange, patrolRange); 125 | 126 | destination = new Vector3(this.transform.position.x + xPos, this.transform.position.y, this.transform.position.z + zPos); 127 | 128 | if (Physics.Raycast(destination, -transform.up, 2f, groundMask)) 129 | { 130 | destinationSet = true; 131 | } 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /ShootScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class ShootScript : MonoBehaviour 7 | { 8 | 9 | //Effect and Cause 10 | public float shotClock; 11 | 12 | public float range; 13 | public float damage; 14 | public float fireRate; 15 | public float reloadTimer; 16 | public float timerReset; 17 | public float ammo; 18 | public float magSize; 19 | 20 | public ParticleSystem muzzleFlash; 21 | 22 | public GameObject impactFlash; 23 | 24 | public Camera mainCam; 25 | 26 | public KeyCode R; 27 | 28 | public Text txt; 29 | 30 | public Transform reloadBar; 31 | 32 | public Image reloadWhite; 33 | public Image reloadBack; 34 | 35 | public float reloadPct; 36 | 37 | // Start is called before the first frame update 38 | void Start() 39 | { 40 | ammo = magSize; 41 | timerReset = reloadTimer; 42 | 43 | reloadWhite.enabled = false; 44 | reloadBack.enabled = false; 45 | 46 | } 47 | 48 | // Update is called once per frame 49 | void Update() 50 | { 51 | if (this.gameObject.tag == "Uzi") 52 | { 53 | 54 | if (ammo < 10) 55 | { 56 | txt.text = "0" + ammo + "/" + magSize; 57 | } 58 | else 59 | { 60 | txt.text = ammo + "/" + magSize; 61 | } 62 | 63 | } 64 | else 65 | { 66 | txt.text = ammo + "/" + magSize; 67 | } 68 | 69 | 70 | if (shotClock >= 0) 71 | { 72 | shotClock -= Time.deltaTime; 73 | } 74 | 75 | if (Input.GetKeyDown(R)) 76 | { 77 | ammo = 0; 78 | //PlayerHealth.Instance.PlayerDamage(10); 79 | } 80 | 81 | if (ammo == 0) 82 | { 83 | Reload(); 84 | } 85 | 86 | if (this.gameObject.tag == "Uzi") 87 | { 88 | if (Input.GetKey(KeyCode.Mouse0) && shotClock <= 0 && ammo > 0) 89 | { 90 | shoot(); 91 | } 92 | 93 | } 94 | else 95 | { 96 | if (Input.GetKeyDown(KeyCode.Mouse0) && shotClock <= 0 && ammo > 0) 97 | { 98 | shoot(); 99 | } 100 | } 101 | 102 | } 103 | 104 | public void shoot() 105 | { 106 | 107 | muzzleFlash.Play(); 108 | 109 | shotClock = 1f / fireRate; 110 | 111 | ammo--; 112 | 113 | //Shoot bullet 114 | RaycastHit hit; 115 | 116 | if (Physics.Raycast(mainCam.transform.position, mainCam.transform.forward, out hit, range)) 117 | { 118 | Debug.Log(hit.transform.name); 119 | 120 | HealthScript target = hit.transform.GetComponent(); 121 | if (target != null) 122 | { 123 | target.hitMarker(damage); 124 | } 125 | } 126 | 127 | GameObject impact = Instantiate(impactFlash, hit.point, Quaternion.LookRotation(hit.normal)); 128 | Destroy(impact, 1.0f); 129 | } 130 | 131 | public void Reload() 132 | { 133 | 134 | reloadWhite.enabled = true; 135 | reloadBack.enabled = true; 136 | 137 | reloadTimer -= Time.deltaTime; 138 | 139 | if (reloadTimer <= 0) 140 | { 141 | ammo = magSize; 142 | reloadTimer = timerReset; 143 | 144 | reloadWhite.enabled = false; 145 | reloadBack.enabled = false; 146 | 147 | } 148 | 149 | reloadPct = (timerReset - reloadTimer)/timerReset; 150 | 151 | reloadBar.localScale = Vector3.Lerp(reloadBar.localScale, new Vector3(reloadPct, 1, 1), Time.deltaTime * 8f); 152 | 153 | 154 | } 155 | 156 | } 157 | --------------------------------------------------------------------------------