萌新求教,我需要在场景里显示若干红细胞,红细胞模型已经做成了预制体,如何用代码创建多个。在网上找的教程全是用的cc.的,3.0里cc取消了,好多API也改了,没找到3.0.1版本的代码生成模型的代码
instantiate函数
1赞
可以用instantiate
import { _decorator, Component, Node, Prefab, instantiate, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('test')
export class test extends Component {
@property(Prefab)
node_p:Prefab=null;
start () {
for (let index = 0; index < 10; index++) {
let node = instantiate(this.node_p);//instantiate生成预制体物体
node.position = new Vec3(index,1,index);//位置
}
}
}
1赞
复制出来的预制体没有父节点的,你要手动设置父节点
1赞
感谢大佬!我试试
好嘞,感谢大佬!
加个这就好了

语法不严格检查,就好了,tsconfig.json文件直接在加上:
"compilerOptions": {
"strict": false //语法不严格检查
}
1赞
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。



