UGUI 判断元素进入舞台

时间:2022-10-14 04:46:08
void LateUpdate () {
if(!_isLoaded){
RectTransform rectt=this.GetComponent<RectTransform>();
float w=rectt.rect.width*0.01f;
float h=rectt.rect.height*0.01f;
float lowerx=rectt.position.x+rectt.rect.x*0.01f;
float lowery=rectt.position.y+rectt.rect.y*0.01f;
float upperx=lowerx+w;
float uppery=lowery+h;
//Game.W=640,Game.H=960设计尺寸大小
bool isIntoX=lowerx<(Game.W*0.5f*0.01f);
bool isIntoY=uppery>(-Game.H*0.5f*0.01f);
if(isIntoX&&isIntoY){
loadIcon();
}
}
}