I have the following code in Update, on a spawner I’ve made:
function Update () {
//search for the ball physics object in the level
var ballExists = GameObject.FindGameObjectsWithTag("Player");
Debug.Log("variable ballExists is equal to " + ballExists);
if(ballExists == null) {
//press launch button to start spawning a ball
//TO DO - Add control check code so space must be pressed before firing
SpawnBall();
}
}
Using the Debug Log, I have found that this never fires SpawnBall().
Being new to using Javascript, I don’t know if I am just using the result of the search wrong. All the examples in the manual never check if something DOESN’T exist, they iterate through objects that DO exist.
According to the manual, it’s supposed to be passing back a “null” for me if 0 of the objects exist. Instead, my debug line is giving me this:
“variable ballExists is equal to UnityEngine.GameObject[ ]”
I’m guessing because it is equal to UnityEngine.GameObject[ ] instead of null, the if statement never fires. I suppose I could get around this by checking if it returns “UnityEngine.GameObject[ ]”, but I would rather know how to properly read the answer Unity is passing back. ![]()
Is there something special I need to do with the stuff it’s passing back to me?