- Home /
How to check for an empty array?
I want to check if all of the 'gems' have been picked up. I do this by using: if (GameObject.FindGameObjectsWithTag("Gem").Length == 0). I have no errors in unity and the game is running. The problem is once the player picked up all the 'gems' and went to the exit portal, nothing happens. I have also tried using:(GameObject.FindGameObjectsWithTag("Gem").Length != 0) with an else statement but this failed too. have no idea what could cause this. thanks in advance.,I am trying to see if all of an object has been destroyed (by the player colliding with it) and then do it so they can go to the next level using: if (GameObject.FindGameObjectsWithTag("Gem").Length == 0). I have no errors, but When the player picks up all the gems and goes to the finish level portal, nothing happens. i've tried using (GameObject.FindGameObjectsWithTag("Gem").Length != 0) and the an else statement and it didn't work. I have no idea what could cause this issue. Thanks
That is the correct way to check for an empty array. Have you tried putting a Debug.Log to see how many gems it thinks are in that array? Maybe print out the names of those objects?
Answer by unity_hosein · Nov 13, 2021 at 04:04 AM
check your pick up script. maybe that script is wrong
Follow this Question
Related Questions
Tagged objects not returning value 0 Answers
Multiple Cars not working 1 Answer
finding clones and destroying them doesn't work 0 Answers
Distribute terrain in zones 3 Answers
Array performance on android device 1 Answer