I’m not at home right now to test this theory I have so I’ll ask here. A little background first. In an effort to help me learn Unity3D better I am taking a game I created in flash and trying to recreate it. Its a 2D grid based strategy game which I created for the Ludum Dare a couple of years back.
My background sprite is 300x300 and the select box sprite is 20x20 so my grid is 15x15. When you move the mouse, which is linked to the select box, your only able to move the box within that 15 by 15 grid. I’ve gotten this to work but I’m having difficulty with it moving every 20 spaces like it does in the flash version.
My theory is this:
mPos = Camera.main.ScreenToWorldPoint(input.mousePosition);
x = mPos.x;
y = mPos.y;
if(x % 20 = 0 && y % 20 = 0)
{
transform.position = mPos;
}
I will be the first to admit I’m still learning so the above code may have errors in it. Am I on the right track? Will this does what I want it to do?
-KunoNoOni