Hi everyone,
Been watching some Youtube videos about learning how to prog in Unity and C#. Got some questions and couldn’t Google answers, because I hadn’t found how to question it properly.
public static TextMesh CreateWorldText(string text, Transform parent = null, Vector3 localPosition = default(Vector3), int fontSize = 40, Color? color = null, TextAnchor textAnchor = TextAnchor.UpperLeft, TextAlignment textAlignment = TextAlignment.Left, int sortingOrder = sortingOrderDefault) {
if (color == null) color = Color.white;
return CreateWorldText(parent, text, localPosition, fontSize, (Color)color, textAnchor, textAlignment, sortingOrder);
}
Could you explain, please:
- What is ‘?’ operator after Color class? Is it regular conditional operator? Than why it doesn’t have consequent : alternative? And why it equals something?
I tried to find it out in the C# docs, but I’ve failed Maybe didn’t look close enough.
- Why class Color in return type parameters is in parentheses? What does that mean? Removing parentheses gives a syntax error with color varuable. And removing the whole ‘(Color)’ gives an error with ‘parent’ and ‘text’ (can’t convert to string and transform accordingly)
Sorry for grammar and noob questions
Would be gratefull for any explanations or docs.