Unity Mobile Development (1): 2d camera follow

Source: Internet
Author: User

Unity starting with 4.3, Unity3d began to call unity, removing the suffix because the 4.3 version later joined the powerful native 2d development environment. For unity engineers who are familiar with 3d development, they don't need too much time to get used to the development of 2d. Today, 2d cameras follow. Because it is a 2d environment, we consider that there is a z-axis missing in the axial direction, we only need to consider the x and Y axes. Because it is a horizontal version, we lock the x-axis of the camera so that it does not allow the camera to follow the main character and cause the camera to shake (the effect is that the camera is set to everything from the object, the experience is not very good. ) code is as follows:

1. Define a public transform target.

Public Transform target;//The location information used to get the target.

2. Updates to the Update method are as follows:

Vector3 pos=transform.position;

pos.x=target.position.x;

Transform.position=pos;

is to assign the x-axis of the target to the x-axis of the camera. Make the X-values equal so that the camera has been shifted in the x-axis direction along with the protagonist.

So easy!

Unity Mobile Development (1): 2d camera follow

Related Article

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.