Sensing amount of spots being used in array

So I created an array with a length of 3. But I need to check how many spots contain a value. How can I do this?

What type of data is being stored in the array?

It is a GameObject array.

2 Answers

2

Hi @AceParker
Help us help you by writing a much longer post describing the issue in detail.

Loop through each element in the array, and check using an if statement. If you array is called myArray, then this is how you can do it:

foreach (GameObject obj in myArray){
    if( obj.CompareTag("target") ){
        //do something
    }
}

The above code checks for the objects tag. You can also check for its name or some other attribute.