// Update is called once per frame void Update() { RoadCreator road_creator = this.tool_control.road_creator; // -------------------------------------------------------------------------------------------- // // 查找当前赛车位于哪个方块上 // (方块=将跑道按照前进方向进行分割后的产物) GameObject car_object = this.tool_control.car_object; if (car_object != null) { // 检测赛车所在的方块 // 向赛车的底部发射Ray,和道路发生碰撞 Vector3 start = car_object.transform.position; Vector3 end = start + Vector3.down * 10.0f; is_hitted = Physics.Linecast(start, end, out hit, (1 << LayerMask.NameToLayer("Road Coli"))); if (is_hitted) { this.current_block_index = road_creator.getRoadBlockIndexByName(hit.collider.name); if (this.current_block_index != -1) { // 只有针对赛车所在的前后方块碰撞才会有效 // for (int i = 0; i < road_creator.road_mesh.Length; i++) { if (this.current_block_index - 1 <= i && i <= this.current_block_index + 1) { road_creator.setEnableToBlock(i, true); } else { road_creator.setEnableToBlock(i, false); } } // current_poly_index = hit.triangleIndex / 2; } } // 是否得分?判断 if (!this.is_goaled) { do { if (road_creator.road_mesh == null) { break; } if (this.current_block_index < road_creator.road_mesh.Length - 1) { break; } if (this.current_poly_index < this.goal_poly_index - 1) { break; } this.is_goaled = true; this.goal_audio.PlayOneShot(this.goalAudioClip); } while(false); } } }
// Update is called once per frame void Update() { RoadCreator road_creator = this.tool_control.road_creator; // -------------------------------------------------------------------------------------------- // // 車が走っているのがどのブロックなのかを調べる. // (ブロック=コースを進行方向にそって分割したもの). GameObject car_object = this.tool_control.car_object; if (car_object != null) { // 車がいるブロックを調べる. // 車の真下に向かって Ray を飛ばし、道路とコリジョンをとる. Vector3 start = car_object.transform.position; Vector3 end = start + Vector3.down * 10.0f; is_hitted = Physics.Linecast(start, end, out hit, (1 << LayerMask.NameToLayer("Road Coli"))); if (is_hitted) { this.current_block_index = road_creator.getRoadBlockIndexByName(hit.collider.name); if (this.current_block_index != -1) { // 車がいる前後のブロックのみ、コリジョンを有効にする. // for (int i = 0; i < road_creator.road_mesh.Length; i++) { if (this.current_block_index - 1 <= i && i <= this.current_block_index + 1) { road_creator.setEnableToBlock(i, true); } else { road_creator.setEnableToBlock(i, false); } } // current_poly_index = hit.triangleIndex / 2; } } // ゴールした? 判定. if (!this.is_goaled) { do { if (road_creator.road_mesh == null) { break; } if (this.current_block_index < road_creator.road_mesh.Length - 1) { break; } if (this.current_poly_index < this.goal_poly_index - 1) { break; } this.is_goaled = true; this.goal_audio.PlayOneShot(this.goalAudioClip); } while(false); } } }