I want to generate bubble randomly in my screen.When bubble is generated in one place then other bubble can not generated near of its radius 1 area. means bubbles can not collide or triggered with any other bubbles.
How can i do it ?
public void GenerateBubble ()
{
newBubbleXPos = Random.Range (-7, 7);
newBubbleYPos = Random.Range (-3, 3);
bubbleClone = (GameObject)Instantiate (bubblePrefab, new Vector3 (newBubbleXPos, newBubbleYPos, 0), Quaternion.identity);
bubbleList.Add (bubbleClone);
if (bubblePosList.Contains (bubbleClone.transform.position)) {
bubbleClone.transform.position=new Vector3(Random.Range (-7,7),Random.Range (-3,3),0);
}
bubblePosList.Add (bubbleClone.transform.position);
bubbleClone.transform.parent = UIManager.instance.CurrentLevel.transform;
GLOBALS.bubbleCounter++;
}
In this my code every bubble is generated in different position but it can collide with other bubble means i want to generate new bubble not same position as well as it can not collide also. My bubble collider’s radius is 1.