Skip to content

Instantly share code, notes, and snippets.

@curious-username
Last active Oct 14, 2021
Embed
What would you like to do?
player ammo code
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