3.x 3D节点坐标如何转为2D UI坐标?

如题,看了论坛上的一些资料,没搞定,如下工程,为啥转换到UI节点得到的位置是左下角,目标是想让文本位置显示到模型所在地方,但是现在会显示到左下角
import { _decorator, Component, Node, Camera, v3 } from ‘cc’;

const { ccclass, property } = _decorator;

@ccclass(‘Main’)

export class Main extends Component {

@property(Node)

private cube:Node = null;

@property(Node)

private label:Node = null;

@property(Camera)

private uiCamera:Camera = null;

start () {

    this.scheduleOnce(()=>{

        this.fixLabelPosition();

    },1)

}

private fixLabelPosition(){

    let wpos = this.cube.getWorldPosition();

    let localPos = v3();

    this.uiCamera.convertToUINode(wpos, this.label.parent!, localPos);

    this.label.setPosition(localPos);

}

}

NewProject_1.zip (6.2 KB)


相机用错了,换成 3d 相机

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。