Esempio n. 1
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (ballBehavior != null)
        {
            ballBehavior.HandleOnCollisionEnter2D(other);

            float   threshold = 0.01f;
            Vector2 vel       = other.relativeVelocity;
            if (-threshold < vel.x && vel.x < threshold)
            {
                Vector2 desiredDirection = new Vector2(squareBounceRandomVector,
                                                       vel.y);
                rigidbody.velocity        = desiredDirection;
                squareBounceRandomVector *= -1;
            }
            else if (-threshold < vel.y && vel.y < threshold)
            {
                Vector2 desiredDirection = new Vector2(vel.x,
                                                       squareBounceRandomVector);
                rigidbody.velocity        = desiredDirection;
                squareBounceRandomVector *= -1;
            }
        }
    }