Search Unity

Check if Element Exist

Discussion in 'Scripting' started by _Helios_, Sep 5, 2011.

  1. _Helios_

    _Helios_

    Joined:
    Jan 20, 2011
    Posts:
    29
    Hello Everyone,

    How would I check if an element in an array existed. I am using a 3 dimensional array, and if the the element at the 3 indices is undefined it should tell me that it doesn't exist. Ive looked all over the internet but nothing has worked.

    Thanks,
    Austin
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Are you just talking about checking for null? I wouldn't think so, if you're using 3D arrays, but I don't know what else you'd be talking about.

    Code (csharp):
    1. void Awake () {
    2.     Object[,,] objects = {{{this, null}}};
    3.     Debug.Log(objects[0,0,0]);  // name of the script
    4.     Debug.Log(objects[0,0,1]);  // null
    5. }
    Using an if statement with a UnityEngine Object is easy, but some people take issue with the implementation, apparently:
    http://forum.unity3d.com/threads/102849-Remove-implicit-bool-cast-from-UnityEngine.Object!!