- Home /
Question by
Shippety · Jun 05, 2016 at 08:02 PM ·
c#2dprogrammingmousepositioncamera.screentoworld
Tryna get the position of the mouse in world space
I'm trying to spawn an object in a certain position (in a 2d game) where the position is where the player clicks on the screen with the mouse. So I'm using
spawnPos = Camera.main.ViewportToWorldPoint(Input.mousePosition);
to get the point (I think that's where I'm going wrong) and then setting it as a clone's pos with
clone.transform.position = spawnPos;
I've also tried using Camera.screenToWorldPoint, but that didn't seem to do it in this case either. Anyone know a good solution to this? Appreciated! :)
Comment
Best Answer
Answer by TBruce · Jun 05, 2016 at 08:19 PM
try this isnstead
spawnPos = Camera.main.ScreenToWorldPoint(Input.mousePosition)