make code shorter

can somone tell me how to make this code shorter? :eyes:

private void ShowBullets(int howMany)
    {
        if(howMany == 0)
        {
            currentBullets[0].SetActive(false);
            currentBullets[1].SetActive(false);
            currentBullets[2].SetActive(false);
            currentBullets[3].SetActive(false);
            currentBullets[4].SetActive(false);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if(howMany == 1)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(false);
            currentBullets[2].SetActive(false);
            currentBullets[3].SetActive(false);
            currentBullets[4].SetActive(false);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 2)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(false);
            currentBullets[3].SetActive(false);
            currentBullets[4].SetActive(false);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 3)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(false);
            currentBullets[4].SetActive(false);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 4)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(false);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 5)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(false);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 6)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(false);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 7)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(false);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 8)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(false);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 9)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(false);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 10)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(false);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 11)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(false);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 12)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(true);
            currentBullets[12].SetActive(false);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 13)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(true);
            currentBullets[12].SetActive(true);
            currentBullets[13].SetActive(false);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 14)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(true);
            currentBullets[12].SetActive(true);
            currentBullets[13].SetActive(true);
            currentBullets[14].SetActive(false);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 15)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(true);
            currentBullets[12].SetActive(true);
            currentBullets[13].SetActive(true);
            currentBullets[14].SetActive(true);
            currentBullets[15].SetActive(false);
        }
        else if (howMany == 16)
        {
            currentBullets[0].SetActive(true);
            currentBullets[1].SetActive(true);
            currentBullets[2].SetActive(true);
            currentBullets[3].SetActive(true);
            currentBullets[4].SetActive(true);
            currentBullets[5].SetActive(true);
            currentBullets[6].SetActive(true);
            currentBullets[7].SetActive(true);
            currentBullets[8].SetActive(true);
            currentBullets[9].SetActive(true);
            currentBullets[10].SetActive(true);
            currentBullets[11].SetActive(true);
            currentBullets[12].SetActive(true);
            currentBullets[13].SetActive(true);
            currentBullets[14].SetActive(true);
            currentBullets[15].SetActive(true);
        }
    }

check for loops, one option could be something like:

private void ShowBullets(int howMany)
{
    for (int i=0;i<currentBullets.length;i++)
    {
       currentBullets[i].SetActive(i<howMany); // if i is smaller than howMany, then setactive sets to true
    }
}
2 Likes

thank you :smile: this is what i needed