---
title: "レッスン 6.2 - 調査とトラブルシューティング"
content_type: tutorial
url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp?language=ja"
language: ja
difficulty: beginner
duration_minutes: 60
unity_version:
  - "2021.3"
  - "2021.2"
  - "2021.1"
  - "2020.3"
  - "2020.2"
  - "2020.1"
  - "2019.4"
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2021.3"
  - name: "2021.2"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2021.2"
  - name: "2021.1"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2021.1"
  - name: "2020.3"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2020.3"
  - name: "2020.2"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2020.2"
  - name: "2020.1"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2020.1"
  - name: "2019.4"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja&version=2018.4"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-2.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/leccion-6-2-investigacion-y-resolucion-de-problemas.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting-jp.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/6-2gang-josa-mic-munje-haegyeol.md?language=ko"
last_updated: "2026-08-04T14:21:58.000Z"
---

# レッスン 6.2 - 調査とトラブルシューティング

オンライン調査とトラブルシューティングの方法を学びながら、Prototype 1 の車両により現実的な物理挙動と速度計、RPM 表示を追加します。

**概要：**

このレッスンでは、Prototype 1 の車両に速度計と RPM 表示を追加することを試みます。このレッスンでは、新機能を実装したり、プロジェクトのバグをトラブルシューティングしたりする際のオンラインでの調査プロセスを学びます。新しい機能を追加することは、当初の印象ほど簡単ではないことがお分かりいただけると思います。普通はあまりオンラインでの調査を必要としない、予想外のやエラーに必ず突き当たることになるでしょう。このレッスンでは、そのような調査のやり方を学び、自分のプロジェクトでもそれができるようにします。

**プロジェクトの成果物：**

このレッスンの終わりには、車両はより現実に近い物理に従って動作するようになり、スピードメーターと毎分の回転数（RPM）表示が付いた状態になります。

## 1. 自動車が力学に従って動くようにする

> _速度計を実装するために、まず最初にしなければならないのは、力学に従った、実車のような加速、減速の挙動をさせることです。これは Translate を操作する方法とは対照的です。_

[Video](https://connect-mediagw.unity.com/h1/20200728/videos/1df32c4a-ac2d-4194-944f-004044a39f1f_CWC_U6.L2.S1.mp4) ([Transcript (ja_jp)](https://connect-mediagw.unity.com/h1/20220506/5988afe3-22d4-48f5-b4a9-0d5762b82082_216_Lesson_62__Make_the_vehicle_use_forces.en.vtt))

1. Prototype 1 プロジェクトを開き、バックアップを作成します。
2. Translate の呼び出しを車両の Rigidbody に対する AddForce の呼び出しに置き換え、変数「speed」の名前を「horsePower」に変更します。
3. 車両が動くようになるまで horsePower を大きくします。
4. 車両を適切な方向に移動させるには、AddForce を AddRelativeForce に変更します。

![](https://connect-mediagw.unity.com/h1/20190702/learn/images/922673b0-3477-4718-8381-3274ac459706_Screen_Shot_2019_07_02_at_4.25.34_PM.png)

## 2. 車がひっくり返らないようにする

> _車両に実世界の物理を実装しましたが、このままだと非常に簡単に横転してしまいます。車をより安全に運転できるようにするにはどうすればいいでしょうか。_

[Video](https://connect-mediagw.unity.com/h1/20200728/videos/10d10d51-3516-41a9-ba12-a5ec73d741b1_CWC_U6.L2.S2.mp4) ([Transcript (ja_jp)](https://connect-mediagw.unity.com/h1/20220506/7a32e8cf-df70-4fec-b77e-1b000438a5c9_217_Lesson_62_Prevent_car_from_flipping_over.en.vtt))

1. 車両の車輪にホイールコライダーを追加し、半径と中心位置を編集し、車輪の他のコライダーを無効にします。
2. 新しく GameObject centerOfMass 変数を作成し、Start()で playerRb 変数を centerOfMass の位置に代入します。
3. 車両の子オブジェクトとして「Center Of Mass」という名前の空のオブジェクトを作り、再配置し、インスペクターの Center Of Mass 変数に割り当てます。
4. Center Of Mass の位置、速度、およびターン速度の値をいろいろ変えてみて、車両を思い通りに操縦できるような設定にします。

![](https://connect-mediagw.unity.com/h1/20190702/learn/images/d1994dd0-0b9f-4942-8633-ae648265de95_Screen_Shot_2019_07_02_at_4.25.42_PM.png)

## 3. 速度計のディスプレイを追加する

> _ほぼ運転可能な状態になったので、ユーザーインターフェースに速度を表示してみましょう。_

[Video](https://connect-mediagw.unity.com/h1/20200728/videos/5b5b7bfd-6111-4b7c-b2ec-f8ecc9802c15_CWC_U6.L2.S3.mp4) ([Transcript (ja_jp)](https://connect-mediagw.unity.com/h1/20220506/9235fb8c-0479-418b-9513-7e4f252a0266_218_Lesson_62_Add_a_speedometer_display.en.vtt))

1. 新しい「TextMeshPro - Text」を作り速度計に表示するテキストのオブジェクトを作ります。
2. TMPro ライブラリをインポートしてから、TextMeshProUGUI 変数を作り、speedometerText に割り当てます。
3. 速度を管理する新しい float 型変数を作成します。
4. Update() で、速度を mph または kph で計算し、それらの値を UI に表示します。

![](https://connect-mediagw.unity.com/h1/20190702/learn/images/f541b898-1424-428d-9e19-a3c21458cfaa_Screen_Shot_2019_07_02_at_4.25.51_PM.png)

## 4. RPM ディスプレイを追加する

> _多くのカーシミュレーターに搭載されているもう 1 つのクールな機能は、RPM（分あたりの回転数）の表示です。計算方法を考えるのが少々頭を使う部分です。_

[Video](https://connect-mediagw.unity.com/h1/20200728/videos/d2220a0b-931b-44c4-9cce-687cea98f624_CWC_U6.L2.S4.mp4) ([Transcript (ja_jp)](https://connect-mediagw.unity.com/h1/20220506/ffeecbf8-0b5b-4550-876c-16a3dd5b3898_219_Lesson_62_Add_an_RPM_display.en.vtt))

1. 新しく「RPM Text」オブジェクトを作成し、新しく rpmText 変数を作成して、そこに割り当てます。
2. Update() で、モジュロ（剰余）演算子（「%」） を使って RPM を計算し、その値を UI に表示します。

![](https://connect-mediagw.unity.com/h1/20190702/learn/images/61ce4804-8c14-4fd4-aa9e-0f1d9fad7ae8_Screen_Shot_2019_07_02_at_4.26.02_PM.png)

## 5. 空中を走らないようにする

> _車の機能はほぼ完ぺきになりましたが、まだ 1 つだけ大きなバグが残っています。空中にあるときも、車は加速、減速、ターンをしたり、スピードや RPM が増加したりするのです。_

[Video](https://connect-mediagw.unity.com/h1/20200728/videos/731e3785-f3fb-456c-9d94-22b7596b4071_CWC_U6.L2.S5.mp4) ([Transcript (ja_jp)](https://connect-mediagw.unity.com/h1/20220506/44dbcac3-a359-4e48-bf7a-83d901699e8c_220_Lesson_62_Prevent_driving_in_mid_air.en.vtt))

1. allWheels（または frontWheels、backWheels）という名前の新しい WheelCollider のリストを宣言し、インスペクターで各ホイールをそのリストに割り当てます。
2. 新しく int wheelsOnGround を宣言します。
3. bool IsOnGround() メソッドを記述し、すべての車輪が地面に接地している場合は true、接地していない場合は false を返します。
4. 加速、ターン、速度、回転数に関する機能を実装している部分を、車が地面に接地しているかをチェックする if 文で囲みます。

![](https://connect-mediagw.unity.com/h1/20190702/learn/images/659235ef-b385-4352-b801-619bfb69525f_Screen_Shot_2019_07_02_at_4.26.13_PM.png)

## 6. レッスンのまとめ

**新しい概念とスキル**

- Unity Answers、Unity フォーラム、スクリプティング API を検索する
- バグを解決するためのトラブルシューティング
- AddRelativeForce、Center of Mass、RoundToInt
- モジュロ（剰余）演算子（「%」）
- ループしてリストを検索
- bool 型の戻り値を返すカスタムメソッド
