using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UIself : MonoBehaviour
{
[SerializeField]
Vector2 sizeDelta;
float W;
float H;
float sW;
float sH;
RectTransform rt;
// Use this for initialization
void Start()
{
rt = this.GetComponent<RectTransform>();
sW = Screen.width;
sH = Screen.height;
SetPos(sizeDelta);
}
void SetPos(Vector2 v2)
{
rt.sizeDelta = v2 * 9 * Screen.width / (16 * Screen.height);
}
// Update is called once per frame
void Update()
{
if (sW != Screen.width || sH != Screen.height)
{
SetPos(sizeDelta);
sW = Screen.width;
sH = Screen.height;
}
}
}
注意:rt.sizeDelta = v2 * 9 * Screen.width / (16 * Screen.height); 这一句是屏幕宽高比为9:16时做的操作,如果宽高比不是9:16,就得自己改
UGUI的UI自动填充整个屏幕的脚本
最新推荐文章于 2022-02-23 20:51:45 发布