jeudi 5 mai 2022

How can I refactor the mass if-else statement?

How can I refactor the mass if-else statement?? I have lots of big if-else statements in my app, do I need to refactor all this code or just leave it alone?

if (up > 80 && up < 140)
{
    if (distance)
    {
        go.transform.position = go2.transform.position;
    }
    go.transform.Translate(y, 0, x);
}
else
{
    if (down > 140)
    {
        if (distance)
        {
            go.transform.position = go2.transform.position;
        }
        go.transform.Translate(0, -y, x);
    }
    else if (down < 35)
    {
        if (distance)
        {
            go.transform.position = go2.transform.position;
        }
        go.transform.Translate(0, -y, -x);
    }
    else if (down > 35 && down < 140 && right > 0)
    {
        if (distance)
        {
            go.transform.position = go2.transform.position;
        }
        go.transform.Translate(-x, -y, 0);
    }
    else if (down > 35 && down < 140 && right < 0)
    {
        if (distance)
        {
            go.transform.position = go2.transform.position;
        }
        go.transform.Translate(x, -y, 0);
    }
}

How can I refactor the mass if-else statement?? I have lots of big if-else statements in my app, do I need to refactor all this code or just leave it alone?

Aucun commentaire:

Enregistrer un commentaire