C# 把帆布夹在球体上
我有一个球体,它在世界空间中相对于相机移动。我将图像夹持到球体上,使其与球体一起移动。我使用下面的代码来实现这一点。这将附加到球体游戏对象C# 把帆布夹在球体上,c#,unity3d,user-interface,C#,Unity3d,User Interface,我有一个球体,它在世界空间中相对于相机移动。我将图像夹持到球体上,使其与球体一起移动。我使用下面的代码来实现这一点。这将附加到球体游戏对象 public class ClampImage : MonoBehaviour { public Camera FirstpersonCamera; public GameObject image; void Update() { //get the position of the sphere
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;
}
}
我尝试使用相同的代码将画布本身夹紧到球体上,但它没有夹紧到球体上。如何将整个画布夹紧到球体上
更新:
整个画布指的是画布及其子游戏对象,如文本和图像
画布位于PlayerGameobject中。以下是画布和玩家游戏对象的设置
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;
}
}
画布设置:
玩家游戏对象设置:
我已经注册了播放器来代替图像。当我运行代码时,它就完全消失了 如果您将想要的UI项目分组到一个面板中,您可以将面板作为游戏对象放置在“image”变量中,然后您可以根据需要移动面板,所有对象都将随之移动如果您要移动画布,请定义“整个画布”,你调用图像的游戏对象可以是画布
整个画布
以及它的子游戏对象,如文本和图像。正如我所说,当你调用游戏对象图像时,你可以将画布指定给我尝试过的对象,但当我这样做时,图像不会移动。画布在屏幕空间中,使用rect变换。然后将对象放在游戏对象中,不要尝试移动画布,而是移动该对象中的所有对象#