P
P
piffo2020-04-28 01:16:02
C++ / C#
piffo, 2020-04-28 01:16:02

Problem with return?

This method weighs on the character

void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.name == "set5")
        {
            if (wer == 4)
            {
                wer--;
                return;
            }
            if (wer == 3)
            {
                wer--;
            }
            if (wer != 4 || wer != 3)
                wer = 5;
        }
        if (col.gameObject.name == "wall3")
        {
            if (wer == 5)
            {
                wer--;
                return;
            }
            if (wer == 1)
                SceneManager.LoadScene("Level4");
            if (wer != 5 || wer != 1)
                wer = 5;
        }
        if (col.gameObject.name == "wall4")
        {
            if (wer == 2)
            {
                wer--;
                return;
            }
            if (wer != 2)
                wer = 5;
        }
    }

And there is such a problem. Here
if (wer == 5)
            {
                wer--;
                return;
            }

return does not always end the execution of a method. That is, approximately with a chance of 2:10 (I did not reveal the exact pattern), the method continues. And here
if (wer == 4)
            {
                wer--;
                return;
            }

return doesn't work at all and the method continues on.
I understand that there will be similar problems here.
if (wer == 2)
            {
                wer--;
                return;
            }

What could be the problem and how can it be fixed?
PS Do not blame me if I'm stupid and poorly studied (or understood) return. I work with return for the first time.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question