void Start() { Cursor.lockState = CursorLockMode.Locked; HealthText.text = "HP: " + Health.ToString(); AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); MyBody = GetComponent <Rigidbody>(); Col = GetComponent <Collider>(); GroundDistance = Col.bounds.extents.y; }
IEnumerator Fire() { if (CanAttack && CurrentMagazine > 0 && !Reload) { CanAttack = false; CurrentMagazine--; AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); Instantiate(Bullet, StartBullet.transform.position, StartBullet.transform.rotation); if (CurrentMagazine <= 0) { StartCoroutine(StartReload()); Reload = true; } CanAttack = true; yield return(new WaitForSeconds(1f)); } }
IEnumerator StartReload() { yield return(new WaitForSeconds(1f)); if (Ammo > Magazine) { int Num = Magazine; Num = Num - CurrentMagazine; Ammo -= Num; CurrentMagazine = Magazine; } else { CurrentMagazine = Ammo; Ammo = 0; } AmmoText.text = "Magazine: " + CurrentMagazine.ToString() + "/ Ammo:" + Ammo.ToString(); Reload = false; }