public Ball GetNearestBall(Vector3 position) { OpenPoolManager manager = OpenPoolManager.instance; Ball nearest_ball = balls[0]; float nearest_distance = float.MaxValue; for(int i=1; i<balls.Length; ++i) { Ball ball = balls[i]; if(ball.isTracked) { Vector3 pos = manager.ScreenToWorld(ball.position); float d = Vector3.Distance(position, pos); if(nearest_distance > d) { nearest_distance = d; nearest_ball = ball; } } } if(nearest_ball.isTracked) { return nearest_ball; } else { return null; } }
public override void DrawDebug () { GL.Begin (GL.LINES); GL.Color (Color.green); OpenPoolManager manager = OpenPoolManager.instance; foreach(Ball ball in balls) { if(ball.isTracked) { Vector3 from = manager.ScreenToWorld(ball.position); Vector3 direction = new Vector3(ball.velocity.x, 0, -ball.velocity.y) * 50f; // cube GLUtils.DrawCube(from, Config.BALL_RADIUS); // velocity GL.Vertex(from); GL.Vertex(from+direction); } } GL.End (); }