

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    private player: cc.Node = null;
    @property([cc.Node])
    private roads: cc.Node[] = [];
    // LIFE-CYCLE CALLBACKS:
    // onLoad () {}
    //一段路的长
    private road_long: number = 715;
    //重复路段次数
    private road_time: number = 91;

    start() {
        this.init();
    }

    update(dt) {
        this.update_road_with_playerz();
    }

    private init() {
        // this.road_time = this.roads.length - 1;
    }

    private update_road_with_playerz() {
        let p_z: number = this.player.z;
        for (let i = 0; i < this.roads.length; ++i) {
            // console.log(this.roads[i].z - p_z);
            if (this.roads[i].z - p_z > this.road_long) {
                console.log('添加路段')
                this.road_time += 1;
                this.roads[i].z = (this.road_time * this.road_long * -1) + 10;
            }
        }
    }
}
