How can I turn this if statement into a property?

I am learning to refactor and optimize my code, I’ve read using properties instead of an If statement in the Update() function is better design-wise.


Currently this is what the code looks like.

void Update()
    {
        if (transform.position.y <= -10f)
        {
            GameManager.Instance.RestartScene();
            canMove = false;
        }
    }

Basically if the player is below -10 on the y axis the scene restarts.


How can I transform this (pun intended) into a property?

Somewhere you gonna have to check that condition… (if (transform.position.y <= -10f)). Property won’t do that for you.
You can design your game better (e.g. using state machine) to avoid constantly checking for something in Update() call. You can use events if there are multiple objects waiting for something, to avoid checking same thing many times. You can also rely on colliders calls instead of checking soemthing manually.