How to Instantiate from mouse pos?
I have a tile placing system that I designed myself, but the tiles are placed with the lower left corner on the mouse becuase of the way I designed it.
Here are snippets of code:
int mouseX = Mathf.RoundToInt (mousePos.x);
int mouseY = Mathf.RoundToInt (mousePos.y);
Another snippet:
GameObject dirt = Instantiate (mainTiles.dirt, new Vector3 (mouseX + 0.5f, mouseY + 0.5f, 0), Quaternion.identity)as GameObject;
I know exactly what the problem is, in the instantiate there is a +0.5f in the vector3 for x and y. However I need that in order for the tile to be lined with my tile grid. What can I do?
I tried adding 0.5 to the mouseX and mouseY but it didn't help :(
The question title is misleading since you already know how to instantiate from mouse pos. Your problem seems to lie in the rounded position values which are also offset to get the instantiating position.
To help people understand your problem, consider adding a simple image that show what happens now and what is supposed to happen.