If value is multiple of

Hey guys,

Quick programming / unity question.

I want to make an inventory with a 3x3 grid. The highlight starts at 0,0. If player presses right, the highlight moves to 1, 0 and now he’s on the second slot of the inventory.

Now the thing is - if the player is on the third slot and he presses right, the highlight should not just to 4,0, but to 0, -1 (which is slot 4).

And the same thing should happen when the cursor is at 6, 9, 12, 15 - every time the cursor is at a multiple of 3.

Is there a clever way of doing this?

You can use the % operator to do it

if (val % 3 == 0)
{
    //val is a multiple of 3, or 0
}