英文:
Chield gameobject with local postion Vector3.zero, doesn't have same position as parent object
问题
我有以下代码:
relationHint = Instantiate(prefabRelationHint) as GameObject;
relationHint.transform.SetParent(imageObject.transform, false);
relationHint.transform.localPosition = Vector3.zero;
目标是在与imageObject(红色笑脸)相同的位置生成relationHint(带有文本的白色方块)。在检查器中一切看起来都正常,因为relationHint被创建为imageObject的子物体,位置为0,0,0,但在相机中它的位置与imageObject不同。
你做错了什么?
英文:
I have following code:
relationHint = Instantiate(prefabRelationHint) as GameObject;
relationHint.transform.SetParent(imageObject.transform, false);
relationHint.transform.localPosition = Vector3.zero;
Goal is to spawn relationHint (white square with text) at same position as imageObject (Red smile face). Everything look OK in inspector, since relationHint gets created as chield of imageObject and has position 0,0,0, but on the camera it doesn't have same position as imageObject.
What am I doing wrong?
答案1
得分: 1
将HitRelation的枢轴设置为x:0.5,y:0.5。这是中心值。
当你将它设置为(2, 2)时,你在说游戏对象的中心位于(2, 2)点。而当你将localPosition设置为(0, 0, 0)时,这一点位于中心。
英文:
You need to set HitRelation's pivot to x:0.5, y:0.5. This is the center value.
When you make it (2, 2) you're saying that game objects center is in (2, 2) point. And this point is centered when you set localPosition to (0, 0, 0).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论