Skip to content

Instantly share code, notes, and snippets.

@curious-username
Last active October 14, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curious-username/0d1e7bdf3125251db1a5eb4251f8420e to your computer and use it in GitHub Desktop.
Save curious-username/0d1e7bdf3125251db1a5eb4251f8420e to your computer and use it in GitHub Desktop.
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