我在做帮助中的新手教程,结果粘贴了一段代码之后,游戏不能预览

就是加入了下面这段代码,然后游戏不能预览,
提示说:Simulator: 58:TypeError: this.player.getComponent(…) is null
请问,这是什么情况呢?


onLoad: function () {
    // 获取地平面的 y 轴坐标
    this.groundY = this.ground.y + this.ground.height/2;
    // 生成一个新的星星
    this.spawnNewStar();
},

spawnNewStar: function() {
    // 使用给定的模板在场景中生成一个新节点
    var newStar = cc.instantiate(this.starPrefab);
    // 将新增的节点添加到 Canvas 节点下面
    this.node.addChild(newStar);
    // 为星星设置一个随机位置
    newStar.setPosition(this.getNewStarPosition());
},

getNewStarPosition: function () {
    var randX = 0;
    // 根据地平面位置和主角跳跃高度,随机得到一个星星的 y 坐标
    var randY = this.groundY + cc.random0To1() * this.player.getComponent('Player').jumpHeight + 50;
    // 根据屏幕宽度,随机得到一个星星 x 坐标
    var maxX = this.node.width/2;
    randX = cc.randomMinus1To1() * maxX;
    // 返回星星坐标
    return cc.p(randX, randY);
}

var randY = this.groundY + cc.random0To1() * this.player.getComponent(‘Player’).jumpHeight + 50;

猜测应该改为:

var randY = this.groundY + cc.random0To1() * this.node.getComponent(‘Player’).jumpHeight + 50;

如果你有属性 player, 那么检查是否有赋值,如果有,就检查player上是否有挂接 ‘Player’ 脚本。

player,并且已经赋值了。
脚本也挂上去了

我是按教程一步一步做的,结果就出错了

贴个demo看看