So I've got a prefab which I am instantiating from the Resources folder in random places; it is just an image with a SpriteRenderer attached to it at the moment:
go = (GameObject) Instantiate(Resources.Load("alienPink"));
These are instantiated at different locations after every 3 seconds.
I also have a ball with a SpriteRenderer, CircleCollider2D and a RigidBody2D attached to it and i get access to the RigidBody2D as follows:
//ray cast from camera to mouse point to detect hit
RaycastHit2D hit = Physics2D.Raycast(mousePos2D , dir);
. . .
RigidBody2D grabbedObject = hit.collider.rigidbody2D;
//do stuff with grabbedObject including change position
I want to detect when the prefab is completely overlapped by the ball which is transparent so I can start doing stuff to the prefab. I've tried numerous methods including trying to detect an overlap between the Renderer of prefab and the ball's rigidbody2D
to no avail. I've even tried grabbing all the prefabs in scene, getting them into an array and detecting overlaps by going through all of the array in every single update but it just doesn't work:
GameObject[] prefab = GameObject.FindGameObjectsWithTag("enemies"); //returns GameObject[]
Try using Physics2D.OverlapCircle to detect overlaps. Another option worth checking out is: Physics2D.OverlapArea. If these two options only provides a partial solution, try using Physics2D.OverlapPoint by checking multiple points so that each point is required to be overlapped; for example, if the ball is to be completely inside a square check for the overlapping of four points within that square.