三項演算子

Tutorial

intermediate

+0XP

5 mins

(20)

Unity Technologies

三項演算子

三項演算子を使って、IF-ELSE で記述する論理条件をシンプルに短く書く方法を学びます。

Languages available:

1. 三項演算子

TernaryOperator クラスのコード

using UnityEngine;
using System.Collections;

public class TernaryOperator : MonoBehaviour 
{
    void Start () 
    {
        int health = 10;
        string message;

        // これは、変数 "health" の値に基づいてメッセージを選択する
        // 三項演算子の使用例です。
        message = health > 0 ? "Player is Alive" : "Player is Dead";
    }
}

Complete this Tutorial