Preventing Coin Spawning

I’m a little confused as how the coin spawning works. My coin has a Circle Collider 2D and my coin spawner has the following code:

            int numColliders = Physics2D.OverlapCircleNonAlloc(spawnPoint, coinRadius, coinBuffer, layerMask);
            if(numColliders == 0)
            {
                return spawnPoint;
            }

What is this saying…is it saying "If the coin collider doesn’t touch an object on “Layer X”, then it is a valid spawn location? If so, does that mean that all of my walls/rocks/etc where I don’t want the coins to spawn should be on “Layer X”?

The position is checking if there are any colliders on layer x within the coin radius. If there aren’t any, it’s a valid spawn location.

Yes. If this check finds any colliders on the layer within the radius - coins/walls/rocks/etc - it won’t spawn a coin there. It looks to me like the purpose of this check is specifically that; Don’t spawn coins if we have anything in layer x within the radius.

1 Like

Thank you so much :slight_smile:

1 Like

Privacy & Terms