怎么convertToUINode进去多少出来多少,像是没计算过?

以下是代码片段,this.node是Canvas,
sphereNode是通过预制生成的一个3D的球,hpNumNode是一个2d的Label,用来显示球的血量,
我想要把血量显示在球的上面,先不说怎么让它不和球重叠的问题,就下面这段代码,_v3_sphere和_v3_hp竟然是相等的,等于是convertToUINode没有计算过,进去什么就给我吐什么出来了。

但我是照着网上大家的例子写的,没看到哪里写错了啊?

        sphereNode.setPosition(8, randomY, randomZ);
        var _v3_sphere = new Vec3(0,0,0);
        var _v3_hp = new Vec3(0, 0, 0);
        sphereNode.getWorldPosition(_v3_sphere);
        console.log(_v3_sphere);
        var hpNumNode = instantiate(this.hpNum);
        hpNumNode.parent = this.node;
        this.node.getChildByName("Camera").getComponent(CameraComponent).convertToUINode(_v3_sphere, this.node, _v3_hp);
        hpNumNode.setPosition(_v3_hp);

该回答引用GPT:
convertToUINode方法是将3D世界坐标转换为2D屏幕坐标,但是你的代码中,_v3_sphere和_v3_hp的值是相等的,这是因为你没有把_v3_sphere传入convertToUINode方法,而是把_v3_hp传入了,所以_v3_sphere和_v3_hp的值是相等的。

正确的代码应该是:

sphereNode.setPosition(8, randomY, randomZ);
var _v3_sphere = new Vec3(0,0,0);
sphereNode.getWorldPosition(_v3_sphere);
console.log(_v3_sphere);
var _v3_hp = new Vec3(0, 0, 0);
var hpNumNode = instantiate(this.hpNum);
hpNumNode.parent = this.node;
this.node.getChildByName("Camera").getComponent(CameraComponent).convertToUINode(_v3_sphere, this.node, _v3_hp);
hpNumNode.setPosition(_v3_hp);

如还有疑问,可留言帮助解决。