// Get the position of the object under Transform components
float xx; float YY; float ZZ; / * * * initialize position to retain the overall model for model reduction position (Position) * transform.position get the world position * transform.localPosition get local location * * / XX = GameObject.Find ( " the objName " ) .GetComponent <the Transform> () .position.x; YY = GameObject.Find ( " the objName " ) .GetComponent <the Transform> () .position.y; ZZ = the GameObject .find ( " the objName " ) .GetComponent <the Transform> () .position.z; //Provided the position of the object Transform component GameObject.Find ( " the objName " ) .GetComponent <Transform> () = position. New new Vector3 (XX, YY, ZZ);
Wherein postion acquisition and simple to set up, to be noted that the rotation can not be acquired directly with rotation.x, thus obtained decimal number between -1 and 1, it is necessary to obtain a method localEulerAngles.x
Implementation manner; also noteworthy that the rotation is provided, the need to use quaternions Quaternion.Euler (x, y, z).
// get under objects Transform rotation component float rx; float Ry; float rz; / * * * initialize the model retains the overall point of view, the model for the reduction of angle (Rotation) * transform.eulerAngles acquired world model angle * transform.localEulerAngles Get Local model angle * * / RX = GameObject.Find ( " the objName " ) .GetComponent <the Transform> () .localEulerAngles.x; Ry = GameObject.Find ( " the objName " ) .GetComponent <the Transform> () .localEulerAngles.y; Rz GameObject.Find = ( " the objName " ) .GetComponent <the Transform>() .localEulerAngles.z;
// rotation assembly disposed under the object Transform GameObject.Find ( " the objName " ) .GetComponent <Transform> () = .rotation Quaternion.Euler (RX, Ry, Rz);
Reference article: https://blog.csdn.net/weiming8517/article/details/50960918?utm_source=blogxgwz7