---
title: "IF 文"
content_type: tutorial
url: "https://learn.unity.com/tutorial/if-sutetomento?language=ja"
language: ja
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja&version=4.x"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/if-statements.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/if-statements-1.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/if-sutetomento.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/if-mun-v3.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/if-yu-ju.md?language=zh-cn"
last_updated: "2026-08-04T14:23:18.000Z"
---

# IF 文

C# の IF 文を使って、条件に応じてコードの実行を制御する方法を学びます。

IF 文を使ってコード内に条件を設定する方法を学びます。

本チュートリアルは [Beginner Scripting プロジェクト](https://learn.unity.com/project/beginner-gameplay-scripting)に含まれています。

前のチュートリアルは：[Conventions and Syntax](https://learn.unity.com/tutorial/conventions-and-syntax?projectId=5c8920b4edbc2a113b6bc26a)

次のチュートリアルは：[Loops](https://learn.unity.com/tutorial/loops-z2b?projectId=5c8920b4edbc2a113b6bc26a)

## 1. IF 文

[Video](http://www.youtube.com/watch?v=PQihrWCOSic)

```csharp
using UnityEngine;
using System.Collections;

public class IfStatements : MonoBehaviour
{
    float coffeeTemperature = 85.0f;
    float hotLimitTemperature = 70.0f;
    float coldLimitTemperature = 40.0f;
    

    void Update ()
    {
        if(Input.GetKeyDown(KeyCode.Space))
            TemperatureTest();
        
        coffeeTemperature -= Time.deltaTime * 5f;
    }
    
    
    void TemperatureTest ()
    {
        // If the coffee's temperature is greater than the hottest drinking temperature...
        if(coffeeTemperature > hotLimitTemperature)
        {
            // ... do this.
            print("Coffee is too hot.");
        }
        // If it isn't, but the coffee temperature is less than the coldest drinking temperature...
        else if(coffeeTemperature < coldLimitTemperature)
        {
            // ... do this.
            print("Coffee is too cold.");
        }
        // If it is neither of those then...
        else
        {
            // ... do this.
            print("Coffee is just right.");
        }
    }
}
```
