void Update() { // get axis CharacterController controller = GetComponent <CharacterController> (); xInputAxis = Input.GetAxisRaw("Horizontal"); zInputAxis = Input.GetAxisRaw("Vertical"); fireButtonAxis = Input.GetAxisRaw("Fire1"); //point player at mouse Vector3 mousePos = cameraComp.ScreenToWorldPoint(Input.mousePosition); transform.LookAt(new Vector3(mousePos.x, transform.position.y, mousePos.z), Vector3.up); //walking //Vector3 forward = transform.TransformDirection (new Vector3(xCtrlAxis, 0.0f, zCtrlAxis)); //controller.SimpleMove(new Vector3(xInputAxis, 0.0f, zInputAxis) * walkSpeed * Time.deltaTime); controller.SimpleMove(new Vector3(xInputAxis, 0.0f, zInputAxis) * walkSpeed * Time.deltaTime); //reloading if (Clip != 0) { if (Input.GetKeyDown(KeyCode.R)) { StartCoroutine("reload"); } } //shooting if (fireButtonAxis == 1 && Time.time > nextFire) { if (Clip != 0 && reloading == false) { nextFire = Time.time + fireRate; //z is up/down and y is forward. Clip = Clip - 1; if (currentWeapon == "Pistol") { guiWeaponText.text = currentWeapon + "" + Clip + "/" + pistolMaxClip; } else if (currentWeapon == "SMG") { guiWeaponText.text = currentWeapon + "" + Clip + "/" + smgMaxClip; } else if (currentWeapon == "Shotgun") { guiWeaponText.text = currentWeapon + "" + Clip + "/" + shotgunMaxClip; } cameraScript.StartCoroutine(cameraScript.shakeCamera(cameraShake)); for (int i = 0; i < bulletsPerShot; i++) { Instantiate( projectile, muzzle.transform.position, muzzle.transform.rotation * Quaternion.Euler(0, 0, Random.Range(-accuracy, accuracy))); // audio.Play(); } if (currentWeapon == "Shotgun") { StartCoroutine("playShotgunShellEjectSound"); } } } if (Clip == 0 && reloading == false) { reloadGui.text = reloadGuiText; if (Input.GetKeyDown(KeyCode.R)) { StartCoroutine("reload"); } } }