Changing a sprite depending on variables I have code here which will change a sprite depending on the variables called gunUpgrade and moveUpgrade. Any way to make the code simpler or shorter? I'm using Unity 3D.

if (gunUpgrade &gt; 0 &amp;&amp; moveUpgrade &gt; 0)
    {
        if (gunUpgrade == 1)
        {
            // For every moveupgrade, set the sprite to array number
            if (moveUpgrade == 1) { currentSprite = playerSprites[8]; }
            else if (moveUpgrade == 2) { currentSprite = playerSprites[9]; }
            else if (moveUpgrade == 3) { currentSprite = playerSprites[10]; }
            else if (moveUpgrade == 4) { currentSprite = playerSprites[11]; }
        }
        if (gunUpgrade == 2)
        {
            if (moveUpgrade == 1) { currentSprite = playerSprites[12]; }
            else if (moveUpgrade == 2) { currentSprite = playerSprites[13]; }
            else if (moveUpgrade == 3) { currentSprite = playerSprites[14]; }
            else if (moveUpgrade == 4) { currentSprite = playerSprites[15]; }
        }
        if (gunUpgrade == 3)
        {
            if (moveUpgrade == 1) { currentSprite = playerSprites[16]; }
            else if (moveUpgrade == 2) { currentSprite = playerSprites[17]; }
            else if (moveUpgrade == 3) { currentSprite = playerSprites[18]; }
            else if (moveUpgrade == 4) { currentSprite = playerSprites[19]; }
        }
    }
I suggest writing it as

currentSprite = playerSprites[4 * (gunUpgrade + 1) + (moveUpgrade - 1)];


Consider laying out the elements of playerSprites so as to require fewer ±1 operations.

Note that you must ensure that gunUpgrade never exceeds 3, and moveUpgrade never exceeds 4.