// Update is called once per frame void Update() { if (Input.GetKeyDown("f")) { if (bulletsInMagazine > 0 && canFire) { GameObject newBullet = Instantiate(bulletPrefab, pistolDirection.position + pistolDirection.forward + shift, pistolDirection.rotation); Rigidbody r = newBullet.GetComponent <Rigidbody>(); r.velocity = (pistolDirection.forward) * bulletSpeed; bulletsInMagazine--; if (bulletsInMagazine <= 0) { canFire = false; } uISingleton.setBullets(bulletsInMagazine.ToString()); } } if (Input.GetKeyDown("r")) { if (magazines > 0) { canFire = false; StartCoroutine(Reload()); } } }
// Start is called before the first frame update void Start() { uISingleton = UISingleton.Instance; uISingleton.setBullets(bulletsInMagazine.ToString()); uISingleton.setMagazines(magazines.ToString()); }