Exemple #1
0
    void FixedUpdate()
    {
        ball = GameObject.FindGameObjectWithTag("Ball").GetComponent <Ball>();

        BallToFloorCollision();

        foreach (GameObject wallObject in walls)
        {
            Wall wall = wallObject.GetComponent <Wall>();
            Debug.Log(wall.name);
            bool isBallCollidingWithWall = BallToWallCollision(wall);
            if (isBallCollidingWithWall)
            {
                Vector3 normal = wall.GetNormal();
                if (Vector3.Dot(normal, ball.Movement) < 0)
                {
                    //Debug.Log(wall.name);
                    ball.BounceOff(normal, ball.Bounciness * wall.Bounciness);
                }
            }
        }

        foreach (GameObject flipperObject in flippers)
        {
            Flipper flipper = flipperObject.GetComponent <Flipper>();
            Debug.Log(flipper.name);

            bool ballToFlipperCollision = BallToFlipperCollision(flipper);
            if (ballToFlipperCollision)
            {
                Vector3 normal = flipper.GetNormal();
                if (Vector3.Dot(normal, ball.Movement) < 0)
                {
                    //Debug.Log(flipper.name);
                    ball.BounceOff(normal, ball.Bounciness * flipper.Bounciness);
                }
            }
        }
    }