如何在按钮触摸时动态添加GameObject作为地平面的子级?

问题描述 投票:-1回答:1

我希望有一个带有多个按钮(宇航员,无人驾驶飞机,毒气罐等)的界面,当用户按下一个按钮时,这些按钮就会出现在地平面上。

我很难将预制件作为地面飞机舞台的孩子进行动态制作。我也不太确定似乎可以做到的ContentPositioningBehavior脚本的工作。

有人可以帮忙吗?谢谢。

unity3d augmented-reality vuforia android-augmented-reality
1个回答
1
投票

Instantiate()有一个重载,是

Instantiate(Object object, Transform parent)

为了使实例化的gameObjects具有接地平面作为父级,可以将其作为parent参数传递。喜欢:

[SerializeField]
private Transform groundPlane; // Drag ground plane to this in inspector.

private void OnClickAstronautButton()
{
    Instanitiate(astroPrefab, groundPlane);
}

...

也有Transform.parent字段。您可以分配给该字段,例如

astronaut.transform.parent = groundPlane;
© www.soinside.com 2019 - 2024. All rights reserved.