export class gameController extends Component {
id = 0;
onLoad() {
game.addPersistRootNode(this.node);
}
set levelID(value){
this.id = value;
}
常驻节点datanode里挂了一个set代码
changeScene(event,customEventData) {
director.loadScene('gameMenu',this.onSceneLaunched)
}
onSceneLaunched(){
let a = find('dataNode').getComponent('gameController')
a.setId(this.id)
a.setTitle(this.title)
console.log(a)
}
在另一个按钮下的脚本点击事件中一直报错,报错如下
Uncaught TypeError: Cannot read property ‘id’ of undefined
当吧this.id修改成1的时候报错如下
Uncaught TypeError: a.setId is not a function
一直解决不掉不知道是什么原因,另一个地方调用明明是可以成功的
game.addPersistRootNode(this.node);顺便一提,vscode提示已经被废弃,但是也没找到替代品
申明一个全局单例就可以了啊
最起码这样做吧。