A faster way to compare point to each corner?

Is there a nicer way to compare a point to each corner of a rect? I need to check if the green point is within the rect before allowing code to run.

Diagram

Comparing four corners one by one at the moment :

 ...
                if (x > _contraintCorners[0].x && y > _contraintCorners[0].y &&
                    x < _contraintCorners[1].x && y > _contraintCorners[1].y &&
                    x > _contraintCorners[2].x && y < _contraintCorners[2].y &&
                    x < _contraintCorners[3].x && y < _contraintCorners[3].y)
                {
                    //Do movement
                }

Unity has an in-built function:

I don’t know if it’s more performant, but it’s certainly faster to type.

1 Like

Don’t you only need to compare with two of the four corners (any two corners diagonal from each other)?

2 Likes

Yes you’re right, thank you!