Created
September 19, 2014 13:54
-
-
Save takashicompany/7e9c80f0441129e92199 to your computer and use it in GitHub Desktop.
??演算子(null合体演算子)が便利すぎる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Awake() | |
{ | |
BoxCollider boxCollider = GetComponent<BoxCollider>(); | |
if (boxCollider == null) | |
{ | |
boxCollider = gameObject.AddComponent<BoxCollider>(); | |
} | |
} | |
// ===== ↑今ままで / ??演算子を使い始めたら↓ ===== | |
void Awake() | |
{ | |
BoxCollider boxCollider = GetComponent<BoxCollider>() ?? gameObject.AddComponent<BoxCollider>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment