三元运算符

Tutorial

intermediate

+0XP

5 mins

(109)

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