2 Add case specific code
source | link

That is a very slow method and unreliable in case you misspell some naming. Or just rename something. Use references to your SpriteRenderers and simply use them when you need. For example place this in your character code.

[SerializeField] private BodyPartsSpriteRenderers _bodyPartsSpriteRenderers;

// Use example
private void Start()
{
    this._bodyPartsSpriteRenderers._Head.sprite = // Some head sprite
}

[System.Serializable]
public class BodyPartsSpriteRenderers
{
    [SerializeField] private SpriteRenderer _head;
    public SpriteRenderer _Head     { get { return this._head; } }

    [SerializeField] private SpriteRenderer _leftArm;
    public SpriteRenderer _LeftArm  { get { return this._leftArm; } }

    [SerializeField] private SpriteRenderer _rightArm;
    public SpriteRenderer _RightArm { get { return this._rightArm; } }

    [SerializeField] private SpriteRenderer _legs;
    public SpriteRenderer _Legs     { get { return this._legs; } }
}

Specific for your case:

public void EquipItem(Equipment newItem)
{
    switch (newItem._BodyPart) {.........
        case BodyPart.Legs:

            this._bodyPartsSpriteRenderers._Legs.sprite = newItem.icon;

        break;
    ..... }
}

Don't forget to assign them in the inspector or you will get NullReferenceException.

That is a very slow method and unreliable in case you misspell some naming. Or just rename something. Use references to your SpriteRenderers and simply use them when you need. For example place this in your character code.

[SerializeField] private BodyPartsSpriteRenderers _bodyPartsSpriteRenderers;

// Use example
private void Start()
{
    this._bodyPartsSpriteRenderers._Head.sprite = // Some head sprite
}

[System.Serializable]
public class BodyPartsSpriteRenderers
{
    [SerializeField] private SpriteRenderer _head;
    public SpriteRenderer _Head     { get { return this._head; } }

    [SerializeField] private SpriteRenderer _leftArm;
    public SpriteRenderer _LeftArm  { get { return this._leftArm; } }

    [SerializeField] private SpriteRenderer _rightArm;
    public SpriteRenderer _RightArm { get { return this._rightArm; } }

    [SerializeField] private SpriteRenderer _legs;
    public SpriteRenderer _Legs     { get { return this._legs; } }
}

Don't forget to assign them in the inspector or you will get NullReferenceException.

That is a very slow method and unreliable in case you misspell some naming. Or just rename something. Use references to your SpriteRenderers and simply use them when you need. For example place this in your character code.

[SerializeField] private BodyPartsSpriteRenderers _bodyPartsSpriteRenderers;

// Use example
private void Start()
{
    this._bodyPartsSpriteRenderers._Head.sprite = // Some head sprite
}

[System.Serializable]
public class BodyPartsSpriteRenderers
{
    [SerializeField] private SpriteRenderer _head;
    public SpriteRenderer _Head     { get { return this._head; } }

    [SerializeField] private SpriteRenderer _leftArm;
    public SpriteRenderer _LeftArm  { get { return this._leftArm; } }

    [SerializeField] private SpriteRenderer _rightArm;
    public SpriteRenderer _RightArm { get { return this._rightArm; } }

    [SerializeField] private SpriteRenderer _legs;
    public SpriteRenderer _Legs     { get { return this._legs; } }
}

Specific for your case:

public void EquipItem(Equipment newItem)
{
    switch (newItem._BodyPart) {.........
        case BodyPart.Legs:

            this._bodyPartsSpriteRenderers._Legs.sprite = newItem.icon;

        break;
    ..... }
}

Don't forget to assign them in the inspector or you will get NullReferenceException.

1
source | link

That is a very slow method and unreliable in case you misspell some naming. Or just rename something. Use references to your SpriteRenderers and simply use them when you need. For example place this in your character code.

[SerializeField] private BodyPartsSpriteRenderers _bodyPartsSpriteRenderers;

// Use example
private void Start()
{
    this._bodyPartsSpriteRenderers._Head.sprite = // Some head sprite
}

[System.Serializable]
public class BodyPartsSpriteRenderers
{
    [SerializeField] private SpriteRenderer _head;
    public SpriteRenderer _Head     { get { return this._head; } }

    [SerializeField] private SpriteRenderer _leftArm;
    public SpriteRenderer _LeftArm  { get { return this._leftArm; } }

    [SerializeField] private SpriteRenderer _rightArm;
    public SpriteRenderer _RightArm { get { return this._rightArm; } }

    [SerializeField] private SpriteRenderer _legs;
    public SpriteRenderer _Legs     { get { return this._legs; } }
}

Don't forget to assign them in the inspector or you will get NullReferenceException.