- Home /
Question by
zdhickman · Apr 24, 2014 at 12:34 PM ·
cameramousemousepositionscreentoworldpoint
Camera.main.ScreenToWorldPoint works within Unity editor, but not in builds
I have this piece of code:
Vector3 v3T = Input.mousePosition;
v3T.z = 10;
v3T = Camera.main.ScreenToWorldPoint (v3T);
Vector3 maybe = Vector3.MoveTowards(transform.position, v3T, 2F);
Which creates a prefab at the location of the mouse click. This works great in the Unity editor, with any resolution selected. However, when I compile the game, either for standalone Windows in a .exe or for the web, the prefab doesn't spawn at all. Why would this be?
Thank you!
Comment
Could you post the code that instantiates the prefab? Also, what's the value of transform.position? Is it possible you're spawning the prefab somewhere unexpected, out of view, so it appears not to spawn at all?