hello all, i’m building a 2d game, and i have balloons randomly spawning on the screen which will be popped with the user taps/clicks them. i wanted them to overlap and not collide as they have rigidbody2d and colliders attached and i used this code to ensure that they do not collide :
function Start () {
Physics2D.IgnoreLayerCollision(9,10, true);
}
this works great, and the items overlap instead of colliding. i would like however that when two or more balloons overlap each other and are popped (touched/clicked) at the same time they do a combo and the combo effect prefab is spawned at that point where the multiple balloons were popped.
i have this code added to each balloon prefab (there are four different balloons each with different a different color).
var pop : GameObject;
var balloontype : GameObject;
function Update () {
if (Input.GetMouseButtonDown(0))
{
var hitm : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hitm.collider != null && hitm.collider.gameObject == balloontype)
{
Instantiate(burst, hitm.point, Quaternion.identity);
Instantiate(pop, hitm.point, Quaternion.identity);
Destroy (hitm.collider.gameObject);
}
}
}
and i would like to add some code which states that when two eyes are hit at the same time by the ray spawn the prefab with the combo animation in that area, and spawn only one, not two combo prefabs (one on each eye).
i cannot seem to figure out how to get this done… if anyone could help it would be greatly appreciated! thanks in advance!