Example #1
0
    public void ControlEnemyPaddle()
    {
        if (balls.Count == 0)
        {
            return;
        }
        int targetIndex = 0;

        for (int i = 0; i < balls.Count; i++)
        {
            if (balls[i] == null)
            {
                balls.RemoveAt(i);
                i--;
                continue;
            }

            if (balls[i].transform.position.y > balls[targetIndex].transform.position.y)
            {
                targetIndex = i;
            }
        }

        if (balls.Count == 0)
        {
            return;
        }
        PongBall target = balls[targetIndex];

        if (target != null)
        {
            float dx = target.transform.position.x - enemyPaddle.transform.position.x;
            if (dx * dx > 0.35f)
            {
                enemyPaddle.Move(Vector3.right * dx);
            }
        }
    }
Example #2
0
 public void HandlePlayerInput()
 {
     playerPaddle.Move(Vector3.right * GameManager.inputAxis.x);
 }