C# Ternary Operator in Unity! - Intermediate Scripting Tutorial

preview_player
Показать описание
Watch this video in context on Unity Learn:

The Ternary Operator can be thought of as a simple, short hand syntax for an IF-ELSE statement. In this video, you will learn to Ternary Operation to test the condition of a variable.
Рекомендации по теме
Комментарии
Автор

OH THANK YOU, YOU JUST SAVED MY CODE FROM BEING MESSY!!

sliceggjd
Автор

edit: I guess in my example "Player is Barely Alive" would never be reached. in any case I guess the point is to show the "cumbersome"ness of using multiple ternary operators in place of "if-else" structure. my example: *message = (health > 4) ? "Player is Healthy." : (health == 0) ? "Player is Dead" : "Player is Low on Health"; Debug.Log(message);*

0:51 - shouldn't "Player is Barely Alive" and "Player is Dead" be flipped? if (health > 0) "Player is Alive", else if (health == 0) "Player is Dead", else "Player is Barely Alive"? Maybe I'm overthinking the example.

TheFingledorf
Автор

Might not be relevant.
But why barely alive with 0 hp

tylam
Автор

Let me save you some 1 mins of your life

<variable "message"> <is equales to> <is Health greater than 0?> <if true then print "Player is Alive"> <if false then print "Player is Dead">

piztech
visit shbcf.ru