IF 문

Tutorial

Beginner

+10XP

5 mins

(77)

Unity Technologies

IF 문

코드에 IF 문을 사용하여 조건을 설정하는 방법을 알아봅니다.

이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.

이전: 규칙 및 구문

다음: 루프

1. IF 문

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(coffeeTemperature > hotLimitTemperature)
        {
            // 다음을 실행합니다.
            print("Coffee is too hot.");
        }
        // 그렇지 않고 커피 온도가 가장 차가운 섭취 온도보다 낮은 경우
        else if(coffeeTemperature < coldLimitTemperature)
        {
            // 다음을 실행합니다.
            print("Coffee is too cold.");
        }
        // 둘 다 해당하지 않는 경우
        else
        {
            // 다음을 실행합니다.
            print("Coffee is just right.");
        }
    }
}

Complete this Tutorial