public void Update() { if (Equiped) { BulletsNowText.text = BulletsCount.ToString(); BulletsAllText.text = AllBulletsCount.ToString(); if (BulletsCount == 0 && !reload) { Reload(); } if (Input.GetKey(KeyCode.Mouse0) && !delay && !reload) { if (AllBulletsCount <= 0 && BulletsCount <= 0) { if (!soundSource.isPlaying) { soundSource.PlayOneShot(TriggerSound); } return; } if (reloadInZoom) { return; } Shoot(); } if (Input.GetKeyDown(KeyCode.R) && !reload) { Reload(); } if (Input.GetKeyDown(KeyCode.Mouse1)) { scopeCam.enabled = true; aim.active = false; moveController.buf /= 2; animator.SetTrigger("Zoom"); } if (Input.GetKeyUp(KeyCode.Mouse1)) { scopeCam.enabled = false; aim.active = true; moveController.buf *= 2; animator.SetTrigger("DeZoom"); } } }
public override void AddBullets(int b) { if (AllBulletsCount > maxBullets) { return; } AllBulletsCount++; BulletsCountText.text = BulletsCount.ToString(); AllBulletsCountText.text = AllBulletsCount.ToString(); }
private void Shoot() { animator.SetTrigger("Shoot"); delay = true; PlayerMouse.Otdacha(Random.Range(-velocityX, velocityX), 0); CameraMouse.Otdacha(0, Random.Range(0f, velocityY)); soundSource.PlayOneShot(ShootSound); BulletsCount--; BulletsNowText.text = BulletsCount.ToString(); prefabParticular.Play(); RaycastHit hit; if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, range)) { PlayerManager pm = hit.transform.GetComponent <PlayerManager>(); if (pm != null) { pm.MinusHealth(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * 1600f); } if (hit.transform.GetComponent <Destructible>() != null) { hit.transform.GetComponent <Destructible>().DestroyGM(); } if (hit.transform.GetComponent <FragGrenade>() != null) { hit.transform.GetComponent <FragGrenade>().explode = true; } if (hit.transform.GetComponent <EnemyStats>() != null) { hit.transform.GetComponent <EnemyStats>().Damage(damage); } GameObject g = Instantiate(ImpactGoPrefab, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(g, 0.2f); } StartCoroutine("Delay"); }
private void Reload() { if (BulletsCount == MagazineBulletsCount) { return; } if (AllBulletsCount == 0) { return; } if (zoom) { animator.SetTrigger("ReloadInZoom"); } else { animator.SetTrigger("Reload"); } soundSource.PlayOneShot(ReloadSound); int buf = MagazineBulletsCount - BulletsCount; if (buf > AllBulletsCount) { BulletsCount += AllBulletsCount; AllBulletsCount = 0; return; } AllBulletsCount -= buf; BulletsCount += buf; if (AllBulletsCount < 0) { AllBulletsCount = 0; } BulletsNowText.text = BulletsCount.ToString(); BulletsAllText.text = AllBulletsCount.ToString(); }
public void Update() { if (Equiped) { if (!anim.isPlaying) { anim.Play("Inactive"); } BulletsNowText.text = BulletsCount.ToString(); BulletsAllText.text = AllBulletsCount.ToString(); if (BulletsCount == 0) { Reload(); } if (Input.GetKeyDown(KeyCode.Mouse0) && !delay && !barrolAnimation.IsPlaying("Reload") && !anim.IsPlaying("Shoot")) { if (AllBulletsCount <= 0 && BulletsCount <= 0) { soundSource.Stop(); soundSource.PlayOneShot(TriggerSound); return; } anim.Play("Shoot"); barrolAnimation.Play("BarrolRotation"); Shoot(); } if (Input.GetKeyDown(KeyCode.R) && !barrolAnimation.IsPlaying("Reload")) { Reload(); } } }
private void Reload() { if (BulletsCount == 12) { return; } if (AllBulletsCount == 0) { return; } soundSource.PlayOneShot(ReloadSound); barrolAnimation.Play("Reload"); int buf = 12 - BulletsCount; if (buf > AllBulletsCount) { BulletsCount += AllBulletsCount; AllBulletsCount = 0; return; } AllBulletsCount -= buf; BulletsCount += buf; if (AllBulletsCount < 0) { AllBulletsCount = 0; } BulletsNowText.text = BulletsCount.ToString(); BulletsAllText.text = AllBulletsCount.ToString(); }