Exemple #1
0
    private void OnCollisionEnter(Collision collision)
    {
        //Rigidbody of the Red Cube that hits the wall
        Rigidbody RedCubeRigidbody;

        if (collision.gameObject.tag == "Ball")
        {
            if (CatchBallScript.bBallWasCaught == true)
            {
                //Increase score multiplier
                ScoringScript.IncreaseScoreMultiplier(0.25f);
            }
        }

        if (collision.gameObject.tag == "RedCube")
        {
            RedCubeRigidbody = collision.gameObject.GetComponent <Rigidbody>();

            if (RedCubeRigidbody.velocity.y < RedCubeKillBallScript.fCubeMaxSpeed)
            {
                //Add force to the cube to continue its momentum
                RedCubeRigidbody.AddForce(0, -0.5f, 0, ForceMode.Impulse);
            }
            else
            {
                //if the cube is going over the set max speed, then set the velocity of the cube to the max speed while keeping other values as they were
                RedCubeRigidbody.velocity = new Vector3(RedCubeRigidbody.velocity.x, RedCubeKillBallScript.fCubeMaxSpeed);
            }
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        //Rigidbody of the Red Cube that hits the wall
        Rigidbody RedCubeRigidbody;

        if (collision.gameObject.tag == "Ball")
        {
            didBallHitSideWallLeft = true;
            //Increase score multiplier
            ScoringScript.IncreaseScoreMultiplier(0.25f);

            //Note hit for WallsHitNum
            ScoringScript.WallsHitNum += 0.25f;

            CatchBallScript.fSumOfCatchesAndWallHitMult += 0.25f;
        }

        if (collision.gameObject.tag == "RedCube")
        {
            RedCubeRigidbody = collision.gameObject.GetComponent <Rigidbody>();

            if (RedCubeRigidbody.velocity.x < RedCubeKillBallScript.fCubeMaxSpeed)
            {
                //Add force to the cube to continue its momentum
                RedCubeRigidbody.AddForce(0.5f, 0, 0, ForceMode.Impulse);
            }
            else
            {
                //if the cube is going over the set max speed, then set the velocity of the cube to the max speed while keeping other values as they were
                RedCubeRigidbody.velocity = new Vector3(RedCubeKillBallScript.fCubeMaxSpeed, RedCubeRigidbody.velocity.y);
            }
        }
    }
Exemple #3
0
    private void OnCollisionEnter(Collision collision)
    {
        //Rigidbody of the Red Cube that hits the wall
        Rigidbody RedCubeRigidbody;

        if (collision.gameObject.tag == "Ball")
        {
            //Increase score multiplier
            ScoringScript.IncreaseScoreMultiplier(0.25f);

            //Note hit for WallsHitNum
            ScoringScript.WallsHitNum += 0.25f;

            CatchBallScript.fSumOfCatchesAndWallHitMult += 0.25f;

            //The spot where the ball hit the floor
            LocationToDisplayWallHitMult = collision.contacts[0].point;
            //Debug.Log("Contact point: " + collision.contacts[0].point);

            //Increase the y value so that it does not intersect with the floor
            LocationToDisplayWallHitMult = new Vector3(LocationToDisplayWallHitMult.x, LocationToDisplayWallHitMult.y + 1.0f, LocationToDisplayWallHitMult.z);

            StartCoroutine(FadeWallHitMult());

            if (LocationToDisplayWallHitMult.x > -7.0f && LocationToDisplayWallHitMult.x < -4.8f)
            {
                LocationToDisplayWallHitMult.x = -4.5f;
            }

            //Debug.Log("Location of Ball Hit Floor: " + LocationToDisplayWallHitMult.x);

            if (LocationToDisplayWallHitMult.x < 9.0f && LocationToDisplayWallHitMult.x > 6.0f)
            {
                LocationToDisplayWallHitMult.x = 6.0f;
            }

            //Display the UI Game Object showing + 0.25 X Game Object
            BallHitWallMultGameObject.transform.position = LocationToDisplayWallHitMult;
        }

        if (collision.gameObject.tag == "RedCube")
        {
            RedCubeRigidbody = collision.gameObject.GetComponent <Rigidbody>();

            if (RedCubeRigidbody.velocity.y < RedCubeKillBallScript.fCubeMaxSpeed)
            {
                //Add force to the cube to continue its momentum
                RedCubeRigidbody.AddForce(0, 0.5f, 0, ForceMode.Impulse);
            }
            else
            {
                //if the cube is going over the set max speed, then set the velocity of the cube to the max speed while keeping other values as they were
                RedCubeRigidbody.velocity = new Vector3(RedCubeRigidbody.velocity.x, RedCubeKillBallScript.fCubeMaxSpeed);
            }
        }
    }