Question by
Vuvuvi · Mar 11 at 03:14 PM ·
unity 2dreloadgun script
Problem with the gun reloading
Hello !
I'm trying to make a reload on "r' pressing. Every time you press r, there's one more bullet in your magazine and one less in your stock. They are visualized by lights (every time you press "r", a lightbulb goes on on the rifle, and one goes off on the stock).
The problem is that it reloads at full magazine capacity everytime, and not just one bullet. I really don't know what's wrong. Can someone please help ? Thanks.
IEnumerator Reloading()
{
OnReloading.Invoke();
//_animator.SetBool("reloading", true);
yield return new WaitForSeconds(_reloadTime);
_canShoot = false;
LightOnReload();
BackpackLightManager();
MagazineManager();
SetMagazineLight();
_emptyFlickeringLight.SetActive(false);
_canShoot = true;
GameState._isReloading = false;
}
void BackpackLightManager() {
if (backpack < 19)
{
_playerBackpackLight[backpack].SetActive(false);
backpack+=1;
}
else if (backpack == 19)
{
_playerBackpackLight[backpack].SetActive(false);
}
else { Debug.Log("Plus de munitions dans le sac"); }
}
void MagazineManager()
{
if (_magazineCapacity < 4)
{
_magazineCapacity+=1;
}
}
void LightOnReload()
{
if (bulb == 0)
{
Debug.Log("munitions au complet");
}
else if (bulb > 0)
{
_playerBulbLight[bulb].SetActive(false)
bulb-=1;
_playerBulbLight[bulb].SetActive(true)
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotation Flicker in 2d platformer gun 0 Answers
What is wrong with my code? (Weapon Reload) 0 Answers
Reload Function Being Called Multiple Times 0 Answers
Unity crashes because of a certain function 0 Answers
script causes unity to crash 0 Answers