【问题标题】:how to position a UI Canvas at the same point as it's parent game object如何将 UI 画布定位在与其父游戏对象相同的位置
【发布时间】:2017-10-26 10:10:39
【问题描述】:

我制作了一个 UI Canvas 预制件,它有一个空的游戏对象,并附有以下脚本:

float remainderAngle;
Image rotAngleWedge;
Image remAngleWedge;

public Image rotateWedgePrefab;
float zRotation = 0f;

public void PieGraph    (float ringRotateAngle, Transform parentTransform)  {

    remainderAngle = 360f - ringRotateAngle;

    rotAngleWedge = Instantiate (rotateWedgePrefab) as Image;
    rotAngleWedge.transform.position = parentTransform.position;
    rotAngleWedge.transform.SetParent (transform, false);
    rotAngleWedge.color = Color.yellow;
    rotAngleWedge.fillAmount = ringRotateAngle / 360f;
    zRotation = Quaternion.Euler (parentTransform.eulerAngles).z - 45.0f;
    rotAngleWedge.transform.rotation = Quaternion.Euler (new Vector3 (0, 0, zRotation));
    zRotation -= rotAngleWedge.fillAmount * 360f;


    remAngleWedge = Instantiate (rotateWedgePrefab) as Image;
    remAngleWedge.transform.position = parentTransform.position;
    remAngleWedge.transform.SetParent (transform, false);
    remAngleWedge.color = Color.white;
    remAngleWedge.fillAmount = remainderAngle / 360f;
    remAngleWedge.transform.rotation = Quaternion.Euler (new Vector3 (0, 0, zRotation));

}

然后我在使用创建预制件后在父游戏对象脚本中调用了PieGraph 方法。我似乎无法将 UI 画布放置在与其父对象相同的位置。请在下面查看 Canvas 及其子对象的检查器设置图像。我怎样才能将它们放在同一个地方?

UI Canvas Prefab 检查器设置

UI Canvas Prefab 子游戏对象检查器设置

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    您可以尝试将 RenderMode 分配给世界空间。

    【讨论】:

    • 我将其更改为世界空间,但现在图像(rotAngleWedge 和 remAngleWedge)没有出现在场景视图和游戏视图中
    • 你是什么意思?您可以在层次结构中选择画布游戏对象吗?你能在现场找到吗?所有子层次对象的比例和位置呢??
    • 我可以在层次结构中看到它们,但在场景或游戏视图中看不到。当我在层次结构中选择它们时,它们似乎位于正确的位置,但它们不可见。我想为渲染模式设置一个事件相机吗?如果是,应该如何设置?
    • 您的画布中是否有一些图像或文本组件?你确定,所有游戏对象的比例都是正确的吗?您无需额外的相机即可在场景视图中看到它。
    猜你喜欢
    • 1970-01-01
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    相关资源
    最近更新 更多