Unity屏幕适配
//引用头文件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;//引用UI
public class ZUOBt:MonoBehaviour{
public float hight://定义一个float类型的变量来接收屏幕的高
public float width://定义一个float类型的变量来接收屏幕的宽
public Image fun;
public Rectansform red;//获取Image组件
public Vector2 had;//定义一个二维向量
private void Awake(){
hight=Screen.Height;//获取屏幕高
widht=Screen.wisth://获取屏幕宽
}
void Start(){
red=fun.GetComponent<RectTransform>();
red.sizeDelta=new Vector2(width,hight)
had=red.sizeDelta;
red.anchoredPosition=new Voctor2(0-had.x/0.285f,0);
}
}