Unity 3D缩放平面到屏幕尺寸 [英] Unity 3d scale plane to screen size
本文介绍了Unity 3D缩放平面到屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将屏幕尺寸转换为世界尺寸,以便可以按与屏幕相同的比例缩放平面.但这只是让screen2World(0.0f,0.0f,0.0f)吗?
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);
}
推荐答案
您传递到ScreenToWorldPoint(...)
的z
是距相机的z
距离.在0f
处,该点将直接位于中间,因为整个平截头体"都在0f
处到达一点. 0f
以外的任何东西都可以为您带来价值.
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);
}
这篇关于Unity 3D缩放平面到屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文