public void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Ball") { ScoringScript.LaunchGameOverFunction(); } }
public void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Ball") { ScoringScript.LaunchGameOverFunction(); //Play sound effect for missing the ball HoleSFXSource.PlayOneShot(BallBehaviorScript.HoleSFXClip, 0.5f); CatchBallScript.isBallCatchable = false; } }
public void CatchBall() { //Check for collision with ball collider trigger //Use raycast to start detection //Set up raycast hit variable RaycastHit hit; //find cursor position at click Ray ray = PlayerCamera.ScreenPointToRay(Input.mousePosition); //Debug.Log("isBallCatchable: " + isBallCatchable); //Check to make sure player can only catch ball after it hits wall if (isBallCatchable == true) { //Debug.Log("Entering Raycast function"); //determine if cursor position is overlapping with ball if (Physics.Raycast(ray, out hit)) { //Debug.Log("Performing Raycast"); Transform objectHit = hit.transform; //Set the Object's tag that was hit to variable ObjectThatWasHit ObjectThatWasHit = objectHit.tag; //If the object that was hit has a tag of "Ball" if (ObjectThatWasHit == "Ball") { //Increment the number of successful catches CatchesNum += 1; //Call function from Scoring Script to add score ScoringScript.BallCaught(true); //Play sound effect for catching the ball BallSFXSource.PlayOneShot(CaughtBallSFXClip, 0.5f); if (CatchesNum == SpawnMovingObjectScript.ArrayOfWhenToRemoveWallPieces[SpawnMovingObjectScript.RemoveWallCounter]) { //Launch RemoveWallPiece Function RemoveWallPiece(); MainRoomLightSettings.color = Color.blue; //Change wall mat to blue //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[1]; //} } if (CatchesNum == 10) { RotateWallScript.isWallRotating = true; StartCoroutine(RotateWallScript.RotateWall(fRotation)); MainRoomLightSettings.color = Color.red; //Change wall mat to red //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[2]; //} } if (CatchesNum == SpawnMovingObjectScript.ArrayOfWhenToSpawnRedCubes[SpawnMovingObjectScript.SpawnCubeCounter]) { SpawnMovingObjectScript.RandomSpawnPosition = Random.Range(0, (SpawnMovingObjectScript.ObjectSpawnPositionObjects.Count - 1)); SpawnMovingObjectScript.ObjectSpawnPosition = SpawnMovingObjectScript.ObjectSpawnPositionObjects[SpawnMovingObjectScript.RandomSpawnPosition].transform.position; SpawnMovingObjectScript.SpawnObject(SpawnMovingObjectScript.ObjectSpawnPosition); MainRoomLightSettings.color = Color.yellow; //Change wall mat to yellow //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[3]; //} //SpawnMovingObjectScript.ObjectSpawnPositionObjects.RemoveAt(SpawnMovingObjectScript.RandomSpawnPosition); //Debug.Log("Counter: " + SpawnMovingObjectScript.SpawnCubeCounter); if (SpawnMovingObjectScript.SpawnCubeCounter < (SpawnMovingObjectScript.ArrayOfWhenToSpawnRedCubes.Length - 1)) { //Debug.Log("Incrementing Counter"); SpawnMovingObjectScript.SpawnCubeCounter += 1; } } else { //do nothing; } if (CatchesNum == 20) { RotateWallScript.isWallRotating = true; StartCoroutine(RotateWallScript.RotateWall(-fRotation * 2)); MainRoomLightSettings.color = Color.red; //Change wall mat to red //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[2]; //} } if (CatchesNum == 25) { RotateWallScript.isWallRotating = true; StartCoroutine(RotateWallScript.RotateWall(fRotation * 2)); MainRoomLightSettings.color = Color.red; //Change wall mat to red //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[2]; //} } if (CatchesNum == 30) { RotateWallScript.isWallRotating = true; StartCoroutine(RotateWallScript.RotateWall(-fRotation * 2)); MainRoomLightSettings.color = Color.red; //Change wall mat to red //Wall Materials Array: | 0 - Default B/W | 1 - Blue | 2 - Red | 3 - Yellow //for (int i = 0; i < WallPieces.Length; i++) //{ // WallMaterialComponent = WallPieces[i].GetComponent<MeshRenderer>(); // WallMaterialComponent.sharedMaterial = WallMaterials[2]; //} } //Reset ball being spawned after catching KillBallScript.DestroyObject(SpawnBallScript.SpawnedBall); //Prevent player from spamming ball spawn StartCoroutine(WaitFunction(0.25f)); //Fade in Score Text Amount StartCoroutine(ScoringScript.Fade()); HitSideWallRightScript.didBallHitSideWallRight = false; HitSideWallLeftScript.didBallHitSideWallLeft = false; bBallWasCaught = false; } else if (ObjectThatWasHit != "Ball") { if (SpawnBallScript.isBallSpawned == true) { numCounterForMissedCatchesBeforeAd += 1; } //number of missed catches ShowAdScript.numMissedCatches += 1; //ShowAdScript.ShowAdFunction(); //Debug.Log("You missed the ball."); //Fading number each time the ball is caught //ScoringScript.ScoreIncreaseFadeNumberText.text = ScoringScript.fAmountToIncreaseScorePerCatch.ToString(); //Current game score shown in the top left ScoringScript.UICurrentGameScoreText.text = ScoringScript.fCurrentScore.ToString(); //Update the final score text //ScoringScript.EndOfRoundScoreText.text = ScoringScript.fCurrentScore.ToString(); //Update the Ball Speed Multiplier Text //ScoringScript.BallSpeedMultiplierText.text = ScoringScript.fballSpeedMult.ToString(); //Run Function to show the Game Over screen and run calculations ScoringScript.LaunchGameOverFunction(); //Update the high score GameManager.UpdateHighScore(); //Save the player profiles //GameManager.Instance.Save(); } else if (ObjectThatWasHit == "UI") { //Do nothing } } } }