Detect the which portion have ball and which have not,


Actually my question is that how to detect which portion have ball have which have not,like in this image the upper portion have balls and lower have not,so the Spliting line is draw at run time it can be anywhere in game.It is the logic of game Split.I want to implement this logic i also attached the link of this game link text

,

I think the best way to do this is to see if the y position of the ball is higher than the line’s y position or lower and according to that you can see in which portion it is. (change the script to suit your game).

 public GameObject line;
 
 public Dictionary<GameObject, string> GetCorrectPortion() {
	var balls = GameObject.FindGameObjectsWithTag("ball");
	var dic = new Dictionary<GameObject, string>();
 
	foreach (var ball in balls) {
		if (ball.transform.position.y > line.transform.position.y) {
			dic.Add(ball, "top");
		} else if (ball.transform.position.y < line.transform.position.y) {
			dic.Add(ball, "bottom");
		} else {
			//if its exactly on the line?
			continue;
		}
	}
	return dic;
 }

This returns a dictionary which contains all balls and whether they are in top or bottom portion by string. You can access this by doing:

foreach (var dicObj in dic) {
	var key = dicObj.Key; //the gameobject
	var value = dicObj.Value //string containing top or bottom

	//do whatever
}