Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

operator "??" in Unity 4.3

Discussion in 'Editor & General Support' started by Itmindco, Nov 13, 2013.

  1. Itmindco

    Itmindco

    Joined:
    Nov 13, 2013
    Posts:
    3
    Why the operator C# "??" has stopped working after update to Unity 4.3

    this code:
    Code (csharp):
    1. var boxColider = gameObject.GetComponent<BoxCollider> () ?? gameObject.AddComponent<BoxCollider> ();
    not work.

    this code:
    Code (csharp):
    1.  
    2. if (gameObject.GetComponent<BoxCollider> () == null) {
    3.     var boxColider = gameObject.AddComponent<BoxCollider> ();
    4. }
    5.  
    work.
     
unityunity