Example #1
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < balls.Count; i++)
        {
            GameObject b1   = balls[i];
            Ball2D     ball = b1.GetComponent <Ball2D>();

            ball.UpdatePhysics();

            for (int j = 0; j < balls.Count; j++)
            {
                GameObject b2    = balls[j];
                Ball2D     ball2 = b2.GetComponent <Ball2D>();

                if (ball != ball2)
                {
                    if (ball.isCollidingWith(ball2))
                    {
                        handleBallColli(ball, ball2, Time.deltaTime);
                    }
                }
            }

            for (int k = 0; k < holes.Count; k++)
            {
                Hole2D hole = holes[k].GetComponent <Hole2D>();

                if (ball.isInside(hole))
                {
                    b1.SetActive(false);
                    break;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < balls.Count; i++)
        {
            GameObject b1   = balls[i];
            Ball2D     ball = b1.GetComponent <Ball2D>();

            ball.UpdatePhysics();

            for (int j = 0; j < balls.Count; j++)
            {
                GameObject b2    = balls[j];
                Ball2D     ball2 = b2.GetComponent <Ball2D>();

                if (ball != ball2)
                {
                    if (ball.isCollidingWith(ball2))
                    {
                        handleBallColli(ball, ball2, Time.deltaTime);
                        AudioSource.PlayClipAtPoint(hitSound, transform.position);
                    }
                }
            }

            for (int k = 0; k < holes.Count; k++)
            {
                Hole2D hole = holes[k].GetComponent <Hole2D>();

                if (ball.isInside(hole))
                {
                    b1.SetActive(false);
                    if (b1.gameObject.tag == "Player")
                    {
                        gameOver.SetActive(true);
                        Time.timeScale = .25f;
                        Invoke("Reset", 1.0f);
                    }
                    break;
                }
            }
        }
    }