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