Ternary Operator?

The left/right hand seems like a textbook place for a ternary operator:

Instantiate(weaponPrefab,(isRightHanded?rightHandTransform:leftHandTransform));

1 Like

It sure is. It’s what I use in my own code, and I believe we do introduce the concept in a later course in the series.

For those reading this post who haven’t encountered Ternary Operators, they work like this

condition ? trueResult : falseResult

It’s syntactic sugar that the compiler interprets as

if(condition)
{
    return trueResult;
} else
{
    return falseResult;
}
2 Likes

Privacy & Terms