Layers - Official Unity Tutorial
Why Stack Overflow recommends it
Stack Overflow users link it when answering Unity questions that need layers set up, such as filtering collisions, overlap checks or random spawn placement.
Recommended by 3 people across 3 different months, 2018 to 2020.
What it is
A 2m39s official tutorial from Unity's channel showing how to create layers in the Unity editor and assign game objects to them. Layers let unrelated objects share common behavior, such as collision filtering or raycast masks.
What people said
Recommends kantagara · 2018-01 · Stack Overflow · on “Spawning 2d objects randomly, but not overlapping with other objects”
You can learn more about layers here: [this video] For example the only thing I wouldn't like to be checked if it overlaps the circle, is the background, since it doesn't have any influence on the game.
Recommends Ignacio Alorre · 2019-05 · Stack Overflow · on “Bullets instantiate inside wall, doesn't trigger OnCollisionEnter2D”
Since colliders are giving troubles when the GameObject is instantiated inside the other collider. I recommed you to first check if the bullet would be instantiated inside the Wall, and in that case, directly don´t instantiate it. I believe this will make the code more efficient. So first you need to add the Wall in a Layer ( Here [this video] you can see how to create a new layer and assign the wall to that layer). An pass it as parameter to the script you use to instantiate the bullets (the script of the tank for example). public LayerMask wallLayer; You save the transform of the tank in a variable // Variable with position of the Tank Transform _transform; void Awake () { _transform = GetCompo
Recommends Frenchy · 2020-05 · Stack Overflow · on “Objects appeared in each other”
one solution is to test collider if obstacles is near the random position with Physics2D.OverlapCircleAll [LINK] and using Layers [LINK] : of course obstacles have collider... private void SpwanerPaper() { for (int i = 0; i < PlaningSpawn; i++) { if (rndType <= _dbPaperSpawn) { while (true) { var position = new Vector2(Random.Range(-1f, 1f), Random.Range(30f, 70f)); // i have choosen radius 1f, you could increase it if needed Collider2D[] colliders = Physics2D.OverlapCircleAll(position, 1f, obstacleLayer); if (colliders.Length == 0) { //so no obstacles present, spawn here var blot = Instantiate(BlotPref[Random.Range(0, BlotPref.Length)], position, Quaternion.identity); blot.transform.SetPare