unity2D 中UI按钮自动适应屏幕。

最近在搞个RPG 2D小游戏,这里我做的UI适应分辨率用的是屏幕尺寸的变化改变 Camera的orthographicSize来实现UI不会改变。

由于我做的是横版游戏,所以用的是屏幕的宽度来匹配,

自动适配过程:

先定义一个初始化的宽度(就是你的开放尺寸)

	private float devWidth = 480f;
	private float orthographicSize;

根据屏幕宽度来调整相机尺寸。

	void myszie(){
		orthographicSize = devWidth / Screen.width;
		this.GetComponent<Camera>().orthographicSize = orthographicSize;

	}



猜你喜欢

转载自blog.csdn.net/cchgood/article/details/47271517