如何在Unity AR Foundation中将gameObject附加到referencePoint?

时间:2019-07-29 08:04:15

标签: c# unity3d

我正在尝试将正在产卵的产卵点锚定到固定位置。因为它们跟随相机的运动,但它们不应该。

我尝试在脚本中创建referencePoint,它将spawnPoints放置在正确的位置,但是船和spawnPoints仍沿摄像机运动。是的,我将spawnPoints都作为referencePoint的子代。

pos = cannon.transform.position; //same position and rotation as trackedImage
rot = cannon.transform.rotation;
Pose pose = new Pose(pos, rot);
refPoint = aRReferencePointManager.AddReferencePoint(pose);
refPoint.transform.position = new Vector3(pos.x - 2, pos.y + yValueChange, pos.z + 50);

foreach (Boat go in battleshipsGameScript.spawnedBoatList)//each boat added as child of refpoint
{
    //go.gameObject.transform.SetParent(refPoint.transform);
    //go.gameObject.transform.localPosition = new Vector3(0f, 0f, 0f);
}

battleshipsGameScript.spawnPoints[0].transform.SetParent(refPoint.transform);                
battleshipsGameScript.spawnPoints[1].transform.SetParent(refPoint.transform);

此外,当我取消注释go.gameobject行时,船将以0,0,0的位置产卵。整个过程开始出现故障。

0 个答案:

没有答案