The transform (Transform) values in the viewer (Inspector) of any child game object (gameobject) are displayed relative to the transformation (Transform) value of the parent (parented). These values are also referred to as local coordinates (the local coordinate)
So. The coordinates that are set on the U3d interface are their local coordinates.
Convert small icon Toggle (Transform Gizmo Toggles)--affects the scene view to display the icon only for easy operation when rotating and moving the position. Pivot Center Point is the center point of the parent object itself ... Center in the parent object's central point of the entire container ... Global is the universal coordinate system ... Local is a native coordinate system (after rotation, the coordinate direction is changed)
- World Space: We add objects (such as Cube) to the scene, and they are all displayed in world coordinates in the scene. The location coordinates can be obtained by the transform.position.
Screen Space: defined in pixels, in the lower-left corner of the screen (0,0), the upper-right corner (Screen.width,screen.height), and the position of z is measured in the camera's world unit. Note: The mouse position coordinates belong to the screen coordinates, Input.mouseposition can obtain the position coordinates, the finger touch screen is also the screen coordinates, Input.gettouch (0). Position can get a single finger to touch the screen coordinates.
ViewPort Space (viewport coordinates): viewport coordinates are standard and relative to the camera. The lower-left corner of the camera is (0,0), the upper-right corner is (the) point, and the position of z is measured in the camera's world unit. (use not much, anyway I did not use ~ hehe ~)
Draw the coordinate system of the GUI interface: This coordinate system is similar to the screen coordinate system, which is different from the upper-left corner of the screen (0,0) and the lower-right corner (screen.width,screen.height).
World coordinates → screen coordinates: camera. Worldtoscreenpoint (transform.position) so that you can convert world coordinates to screen coordinates. Where camera is the camera object in the scene.
screen coordinates → viewport coordinates: camera. Screentoviewportpoint (Input.gettouch (0). position) so that you can convert screen coordinates to viewport coordinates. Where camera is the camera object in the scene.
viewport coordinates → screen coordinates: camera. Viewporttoscreenpoint ();
- viewport coordinates → World coordinates: camera. Viewporttoworldpoint ();
- Case study draw a picture on the location of the mouse click (about drawing the relationship between the GUI interface coordinate system and the screen coordinate system).[CSharp]View Plaincopy
- Using Unityengine;
- using System.Collections;
- public class Test:monobehaviour {
- //Picture
- Public Texture img;
- //store position coordinates of mouse
- private Vector2 Pos;
- void Ongui ()
- {
- //left mouse click to get the current mouse position
- if (Input.getmousebutton (0))
- {
- pos = input.mouseposition;
- }
- //Draw pictures
- Gui. Drawtexture (new Rect (POS.X,SCREEN.HEIGHT-POS.Y,100,100), IMG);
- }
- }
- Case 2--coordinate display and coordinate transformation (this is the touch aspect.) If you don't have a touchscreen, then remove that if!)[CSharp]View Plaincopy
- Using Unityengine;
- Using System.Collections;
- Public class Test:monobehaviour {
- //Scene of the camera, drag and drop in
- Public camera camera;
- //Scene of the object
- private Gameobject obj;
- void Start ()
- {
- //Initialize
- obj = Gameobject.find ("Plane");
- }
- void Update ()
- {
- //have touch
- if (Input.touchcount > 0)
- {
- Print ("World coordinates" + obj.transform.position);
- Print ("screen coordinates" + input.gettouch (0). position);
- Print (world coordinates → screen coordinates + camera. Worldtoscreenpoint (obj.transform.position));
- Print (screen coordinates → viewport coordinates + camera. Screentoviewportpoint (Input.gettouch (0). position));
- Print (world coordinates → viewport coordinates + camera. Worldtoviewportpoint (obj.transform.position));
- }
- }
- }
Coordinate systems in the U3D