import { _decorator, Component, log, Node, randomRangeInt } from 'cc'; import { ObstacleBehaviour } from './ObstacleBehaviour'; import { GameplayController } from '../GameplayController'; const { ccclass, property } = _decorator; @ccclass('ObstaclesController') export class ObstaclesController extends Component { // @property([ObstacleBehaviour]) // private easyObstacle: ObstacleBehaviour[] = []; // @property([ObstacleBehaviour]) // private mediumObstacle: ObstacleBehaviour[] = []; // @property([ObstacleBehaviour]) // private hardObstacle: ObstacleBehaviour[] = []; @property([Node]) private obstaclesSet: Node[] = []; protected onEnable(): void { GameplayController.Instance().eventSpawnObstacle.on("SpawnObstacle", this.RandomSetObstacle, this); // this.RandomSetObstacle(); } private RandomSetObstacle(): void { //let random = randomRangeInt(0, this.obstaclesSet.length); setTimeout(() => { let random = randomRangeInt(0, this.obstaclesSet.length); this.obstaclesSet.forEach(element => { element.active = false; }); this.obstaclesSet[random].active = true; }, 200); } }