Unity 3d scale plane to screen size

2019-09-18 01:37发布

I want to transfer my screen size to world size so I can scale my plane with the same ratio as my screen. But it just makes screen2World (0.0f,0.0f,0.0f)?

void Awake()
{
    Vector3 screen2World = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,0.0f));
    background.localScale = new Vector3(screen2World.x,1.0f,screen2World.y);
    print(screen2World);
}

标签: unity3d
1条回答
等我变得足够好
2楼-- · 2019-09-18 02:24

The z you pass into the ScreenToWorldPoint(...) is the z distance from the camera. At 0f the point will be directly in the middle, as the entire Frustum comes to a point at 0f. Anything other than 0f will give you a value.

public float distance = 100f;
void Awake()
{
    Vector3 screen2World = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,distance));
    background.localScale = new Vector3(screen2World.x,1.0f,screen2World.y);
    print(screen2World);
}
查看更多
登录 后发表回答