I have two game objects named A
and B
, just as follows:
I want to move object B
to this virtual line without any rotation so that the destination is B'
. What I have are transformation of object A
and B
. I'm brand new to Unity3D and its APIs, so I don't know how should I get this done.
Answer
The simplest and non mathematical (noob) way to do this is to make Game object B a child of Game object A , then make local position x as zero and remove B from the parent A.
B.transform.parent = A.transform;
B.transform.localPosition = new Vector3 (0, B.transform.localPosition.y, B.transform.localPosition.z);
B.transform.parent = null;
No comments:
Post a Comment