So here is my problem in a nutshell: I want to know how spawn an object in the middle of the screen, which means I want find the screen's width and height values in World units.
Camera Position: 0,23,-10
Camera Rotation: 60,0,0
So I have tried this:
Vector3 screenWorldSize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, -10));
// In the Update function
If(Input.GetKeyDown(Keycode.P))
{
GameObject tempObject = Instantiate(gamePrefab);
tempObject.transform.position = new Vector3(screenWorldSize.x, 1.5f, 10f);
}
But the tempObject position is not correct (Not in the middle), So I tried to Debug.Log(screenWorldSize)
and I get this result (-10.3, 28.8, -20.0)
I tried using Camera.main.ViewPortToWorldPoint()
with (0,0,-10)
and (1,0,-10)
and I got almost the same result.
Here is an image of the scene..
Is there something that I don't understand? How to get the screen edges in World points?