将画布固定到球体上

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

我有一个相对于摄影机在世界空间中移动的球体。我将图像钳位到球体上,以使其随球体一起移动。我正在使用以下代码来做到这一点。这是附加到球形游戏对象上的。

 public class ClampImage : MonoBehaviour
 {

     public Camera FirstpersonCamera;
     public GameObject image;

     void Update()
     {
        //get the position of the sphere in the worldspace
        Vector3 spherePosition = FirstpersonCamera.WorldToScreenPoint(this.transform.position);
        //assign the world position of the sphere to the image
        image.transform.position = spherePosition;

      }
  }

我尝试使用相同的代码将Canvas自身固定到球体,但未将其固定到球体。如何将整个画布固定到球体上?

更新:

整个画布指的是画布及其子游戏对象,例如文本和图像。

画布位于PlayerGameobject中。以下是画布和玩家Gameobject的设置。

画布设置:

Canvas

玩家游戏对象设置:

Player

我已经在图像上注册了播放器。当我运行代码时,它完全消失了。

c# unity3d user-interface
1个回答
2
投票

[如果在面板中将所需的UI项进行分组,则可以通过将面板放置在“ image”变量中作为GameObject来移动面板,然后可以根据需要移动面板,所有对象都将随之移动] >

© www.soinside.com 2019 - 2024. All rights reserved.