예제 #1
0
    void Update()
    {
        //Checks whether another block must be generated
        this.block_creation_timer += Time.deltaTime;
        if (this.block_creation_timer >= this.block_creation_frequency)
        {
            this.block_creation_timer = 0;

            //Performs spatial displacement for the Perlin Noise module
            this.point_z += this.point_shift_step * Time.timeScale;

            //Checks if this block is the first to be generated
            if (this.track_piece != null)
            {
                //Creates a new block
                TrackPiece new_track_piece = new TrackPiece();
                //Sets the new block as child of the previous block so that the asset perform the fitting
                new_track_piece.SetParentNode(this.track_piece);
                //Stores the reference to the new block
                this.track_piece = new_track_piece;
            }
            //If this is the first block
            else
            {
                this.track_piece = new TrackPiece();
            }

            //Adds self destruction script
            if (self_destruct_blocks)
            {
                SelfDestruction self_destruction = this.track_piece.GetGameObject().AddComponent <SelfDestruction>();
                //Sets the life span
                self_destruction.life_span = this.blocks_life_span;
            }

            //Applies the settings in the new block
            TrackPieceEditor track_piece_editor = track_piece.game_object.GetComponent <TrackPieceEditor>();
            track_piece_editor.seed    = this.seed;
            track_piece_editor.point.z = this.point_z;
            //Calls internal configuration process of the block
            track_piece_editor.Setup();
            //Performs block generation based on configuration parameters
            (new TrackPieceGenerator()).Generate(track_piece);
            //Eliminate previous block reference from the current block, as it is no longer necessary to keep connection between the two
            track_piece.SetParentNode(null);
        }
    }
예제 #2
0
    void Start()
    {
        //Generates track
        TrackPiece track_piece = null;

        for (int block = 0; block < this.blocks_count; ++block)
        {
            //Performs spatial displacement for the Perlin Noise module
            this.point_z += this.point_shift_step * Time.timeScale;

            //Checks if this block is the first to be generated
            if (track_piece != null)
            {
                //Creates a new block
                TrackPiece new_track_piece = new TrackPiece();
                //Sets the new block as child of the previous block so that the asset perform the fitting
                new_track_piece.SetParentNode(track_piece);
                //Stores the reference to the new block
                track_piece = new_track_piece;
            }
            //If this is the first block
            else
            {
                track_piece = new TrackPiece();
            }

            //Applies the settings in the new block
            TrackPieceEditor track_piece_editor = track_piece.game_object.GetComponent <TrackPieceEditor>();
            track_piece_editor.seed    = this.seed;
            track_piece_editor.point.z = this.point_z;
            //Calls internal configuration process of the block
            track_piece_editor.Setup();
            //Performs block generation based on configuration parameters
            (new TrackPieceGenerator()).Generate(track_piece);
            //Eliminate previous block reference from the current block, as it is no longer necessary to keep connection between the two
            track_piece.SetParentNode(null);
        }
    }