按照文档(https://docs.cocos.com/creator3d/manual/zh/scripting/create-destroy.html)的代码,代码如下:
import { _decorator, Component, Prefab, instantiate, director } from "cc";
const { ccclass, property } = _decorator;
@ccclass("test")
export class test extends Component {
@property({type:Prefab})
private target: Prefab = null;
start(){
let scene = director.getScene();
let node = instantiate(this.target);
node.parent = scene;
node.setPosition(0,0,0);
}
}
运行时出现了错误,提示为:
Uncaught TypeError: Cannot set property 'parent' of null
请问为什么?
