public void FireWeapon() { WeaponManager.WeaponProfile gun = WeaponManager.instance.GetCurrentWeapon(); gun.timer = 0; gun.firing = true; SoundManager.instance.playSound(gun.sounds[Random.Range(0, gun.sounds.Count - 1)]); if (gun.animator) { gun.animator.Play(gun.animationToPlay); } }
void Update() { WeaponManager.WeaponProfile gun = WeaponManager.instance.GetCurrentWeapon(); if (gun.firing) { gun.timer += Time.deltaTime * gun.speed; gun.timerUnscaled += Time.deltaTime; gun.timer = Mathf.Clamp01(gun.timer); //Dirty bullshit for idiots if (gun.name == "Minigun") { WeaponManager.instance.barrelsA.SetActive(gun.timer > .5); WeaponManager.instance.barrelsB.SetActive(gun.timer < .5); } if (gun.muzzleFlash && gun.timerUnscaled > 0.1f) { gun.muzzleFlash.enabled = false; } if (gun.firedAngled != 0) { Vector3 weaponRot = gun.weaponRecoilTransform.localRotation.eulerAngles; weaponRot.x = gun.animationCurve.Evaluate(gun.timer) * gun.firedAngled; gun.weaponRecoilTransform.localRotation = Quaternion.Euler(weaponRot); } if (gun.timer >= 1.0f) { gun.firing = false; gun.timer = 0; gun.timerUnscaled = 0; } } }
// Update is called once per frame void Update() { if (GameStateManager.instance.GetState() != GameStateManager.GameStates.STATE_GAMEPLAY) { return; } gunBarrel.rotation = playerCamera.rotation; if (Input.GetMouseButton(0) && WeaponManager.instance.CanFireCurrentWeapon()) { recoilClass.FireWeapon(); WeaponManager.WeaponProfile currentGun = WeaponManager.instance.GetCurrentWeapon(); CameraShake.instance.Shake(currentGun.shakeAmount); if (currentGun.muzzleFlash) { currentGun.muzzleFlash.sprite = WeaponManager.instance.muzzleFlashSprites[Random.Range(0, WeaponManager.instance.muzzleFlashSprites.Count)]; currentGun.muzzleFlash.enabled = true; } if (currentGun.isProjectile) { ProjectileManager.instance.FireProjectile(gunBarrel.position, Camera.main.transform.rotation, true); } else { for (int i = 0; i < currentGun.shots; i++) { Vector3 forwardVec = playerCamera.rotation * GetRandomInsideCone(currentGun.angleDeviation) * Vector3.forward; RaycastHit hit; Vector3 start = gunBarrel.position; Vector3 end = start + forwardVec * maxLineTraceRange; bool isHit = Physics.Linecast(start, end, out hit); if (isHit) { LineManager.instance.ShowLine(start, hit.point); if (hit.rigidbody) { Enemy e = hit.rigidbody.GetComponent <Enemy>(); if (e) { e.OnDeath(); } else { ImpactManager.instance.ShowImpact(hit.point); } } else { ImpactManager.instance.ShowImpact(hit.point); } } else { LineManager.instance.ShowLine(start, end); } } } } }