跟手册学习:快速上手:制作第一个 2D 游戏。 遇到的问题

根据官方文档学习: 快速上手:制作第一个 2D 游戏
前面都很顺利,到“ 游戏管理器(GameManager)”这一节最后的时候,文档上说

“ 此时如果我们在 GameManagerstart 内调用 generateRoad 来创建地图:

start() {
    this.generateRoad()
}

运行游戏后可以观察到地图的生成的情况:”

https://docs.cocos.com/creator/manual/zh/getting-started/first-game-2d/images/gen-road.png

我这里显示还是一个方块。并没有跟文档一样 地图方块都出来

import { _decorator, CCInteger, Component, instantiate, Prefab, Node } from 'cc';
import { BLOCK_SIZE, PlayerController } from './PlayerController';
const { ccclass, property } = _decorator;

enum BlockType {
    BT_NONE,
    BT_STONE,
};

@ccclass('GameManager')
export class GameManager extends Component {

    @property({ type: Prefab })
    public boxPrefab: Prefab | null = null;

    @property({ type: CCInteger })
    public roadLength: number = 50;

    private _road: BlockType[] = [];


    start() {
        this.generateRoad();
    }

    update(deltaTime: number) {

    }

    generateRoad() {

        this.node.removeAllChildren();

        this._road = [];
        // startPos
        this._road.push(BlockType.BT_STONE);

        for (let i = 1; i < this.roadLength; i++) {
            if (this._road[i - 1] === BlockType.BT_NONE) {
                this._road.push(BlockType.BT_STONE);
            } else {
                this._road.push(Math.floor(Math.random() * 2));
            }
        }

        for (let j = 0; j < this._road.length; j++) {
            let block: Node | null = this.spawnBlockByType(this._road[j]);
            if (block) {
                this.node.addChild(block);
                block.setPosition(j * BLOCK_SIZE, 0, 0);
            }
        }
    }
    spawnBlockByType(type: BlockType) {
        if (!this.boxPrefab) {
            return null;
        }

        let block: Node | null = null;
        switch (type) {
            case BlockType.BT_STONE:
                block = instantiate(this.boxPrefab);
                break;
        }

        return block;
    }

}

这是我做到这一步的代码,后面遇到相机不跟随移动,又卡住了,这官方教程太看悟性了,很无语

严重怀疑预制体没有拖到配置里,你打印一下 block 有没有生成就知道了。

我也遇到了这个问题但是block有生成的

找到问题了,是因为的position的问题导致看不到地图生成