Exemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject == PlayerRacket)
        {
            float   y   = Player_script_ref.hitPoint(ball_rb.position);
            Vector2 dir = new Vector2(ball_rb.velocity.x, y).normalized;
            speed           += start_speed / 100;
            ball_rb.velocity = dir * speed;
            //Debug.Log("Ball velocity: " + ball_rb.velocity.ToString());
            score           += 1;
            Score_label.text = "Score: " + score;
        }

        //Add some bouncyness to top and bot wall
        else if (collision.gameObject.tag == "TopWall")
        {
            ball_rb.velocity = new Vector2(ball_rb.velocity.x, ball_rb.velocity.y - 1f);
        }

        else if (collision.gameObject.tag == "BotWall")
        {
            ball_rb.velocity = new Vector2(ball_rb.velocity.x, ball_rb.velocity.y - 1f);
        }
    }