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); } }
/// <summary> /// Destroys the player object and plays the explosion animation. /// </summary> public void DestroyPlayer() { if (explosionPrefab != null) { var explosion = Instantiate(explosionPrefab, _player.transform.position, Quaternion.identity); explosion.transform.SetParent(_rootFolder.transform); SelfDestruction sd = explosion.AddComponent <SelfDestruction>(); sd.SetDelay(1.0f); // Cartoon explosion is kinda weird - use hardcoded length! //sd.SetDelay(explosionPrefab.GetComponent<ParticleSystem>().main.duration - 0.1f); } else { Debug.Log("No explosion Prefab found!"); } Destroy(_player); }