Turning The Mesh Renderer Back On Problem

I am having a lot of trouble trying to turn the mesh renderer for an object on. I can successfully turn it off, but setting enabled to true just isn't working to turn it back on...

By the way, the script is going to be used to change weapons in the game, e.g. turn the AK47 renderer off, and turn the Revolver renderer on.

Here is my code:

function ChangeWeapon()
{
    for(var i = 0; i <= weapons.Length; i++)
    {
        if(eqWeapon == i)
        {

            weapons[eqWeapon].GetComponent("MeshRenderer").enabled = true;
        }
        else
        {

            weapons[eqWeapon].GetComponent("MeshRenderer").enabled = false;
        }
    }
}   

Thanks in advance!

I would not use a for loop for this.

I would use a switch to change the renderer.

Inside your function just set a variable to whatever the current weapon is, and set another to whatever the new weapon will be. Then in your switch case statement, have something like:

weapons[oldWeapon].GetComponent("MeshRenderer").enabled = false; weapons[newWeapon].GetComponent("MeshRenderer").enabled = true; break;