Last active
October 14, 2021 01:09
-
-
Save curious-username/0d1e7bdf3125251db1a5eb4251f8420e to your computer and use it in GitHub Desktop.
player ammo code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int _ammoCount = 15; | |
[SerializeField] | |
AudioSource _ammoEmpty | |
void Update() | |
{ | |
CalculateMovement(); | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
FireLaser(); | |
} | |
void FireLaser() | |
{ | |
_canFire = Time.time + _fireRate; | |
Vector3 offset = new Vector3(0, 1.05f, 0); | |
_ammoCount--; | |
if (_ammoCount < 0) | |
{ | |
_ammoEmpty.Play(); | |
_ammoCount = 0; | |
} | |
else if (_isTripleShotActive == true && _ammoCount >0) | |
{ | |
Instantiate(_tripleShot, transform.position, Quaternion.identity); | |
_laserSound.Play(); | |
} | |
else if(_ammoCount > 0) | |
{ | |
Instantiate(_laserPrefab, transform.position + offset, Quaternion.identity); | |
_laserSound.Play(); | |
} | |
_uiManager.UpdateAmmoCount(_ammoCount); | |
public void AmmoRefill() | |
{ | |
_ammoCount = 15; | |
_powerupSound.Play(); | |
_uiManager.UpdateAmmoCount(_ammoCount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment