官方的摘星星游戏实例,在Game.js里写
spawnNewStar: function() {
newStar.getComponent('Star').game = this;
},
然后在Star.js里写
getDistance :function()
{
var playerPos = this.game.player.getPosition();
},
为什么游戏无法运行并报错
Star.js:13Uncaught TypeError: Cannot read property ‘player’ of undefined
我已经把Game.js里所有的组件都已经挂到Canvas上了。
Star.js也挂到star的prefab上了,还是找不到错误出在哪