Quickly locate the object on the screen in Unity

Source: Internet
Author: User

This allows you to easily pin your UI elements to nine positions on the user's screen: top left, top right, and so on. You can also customize the screen size to facilitate transplantation between multiple devices. this super simple C # extension script provides a method called "screenplacement.

After adding the script to the inverted project, you can easily place your content in one of the nine positions on the screen using screenplacement.

JS Code?
12345 // Place an object in the lower right corner of the screen:transform.ScreenPlacement(ScreenPosition.LowerRight); // Place an object to the bottom right corner of the screen, 60 pixels away from the right side of the screen, and 20 pixels away from the bottom:transform.ScreenPlacement(ScreenPosition.LowerRight,new
Vector2(60,20));

If you want to switch a camera to help display some content, you need to pass the screenposition to your camera to ensure that the content displayed in the camera can be accurately calculated.

JS Code?
12345 // Place an object in the lower-right corner of the screen. For more information, see myinterfacecamera:transform.ScreenPlacement(ScreenPosition.LowerRight, MyInterfaceCamera); // Place an object in the lower-right corner of the screen, 60 pixels away from the right side of the screen, and 20 pixels away from the bottom. For details, refer to myinterfacecamera:transform.ScreenPlacement(ScreenPosition.LowerRight,new
Vector2(60,20), MyInterfaceCamera);

If you need this package, you can download it in my resource area.

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.