Screen-Adaptive code for the UI in Unity

Source: Internet
Author: User

public void Screenuiselfadptation (Transform scaleui)
{
float widthrate = unityengine.screen.width/1920.0f;
float heightrate = unityengine.screen.height/1080.0f;
float postion_x = scaleui.getcomponent<recttransform> (). anchoredposition.x * widthrate;
float postion_y = scaleui.getcomponent<recttransform> (). ANCHOREDPOSITION.Y * heightrate;
Scaleui.localscale = new Vector3 (Widthrate, heightrate, 1);

Scaleui.getcomponent<recttransform> (). anchoredposition = new Vector2 (postion_x, postion_y);
}

UnityEngine.Screen.width and UnityEngine.Screen.height are the screen resolution sizes you want to publish.

1920.0f; x 1080.0f; is the resolution size in the Gam e view when you make the UI.

Screen-Adaptive code for the UI in Unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.