private void FixedUpdate() { collisionDetection.CastRayCast(); /* Since we are applying gravity constantly with our own physics, * we want to check if raycast hit anything, then we set the velocity.y back to 0, * so our ball don't fall through the platform. * We don't want to set velocity.y to 0 when bouncing, or else the ball won't bounce */ ballPhysics.ApplyVerticalCollision(collisionDetection); if (collisionDetection.collidedObject != null) // If our raycast system detects something { ground = collisionDetection.collidedObject.transform; // Set the ground variable to the detected gameobject } // If raycast hits something, we want the ball to bounce up if (collisionDetection.hasCollided) { ballBounce.Bounce(ref ballPhysics.velocity); HapticFeedback.Generate(UIFeedbackType.ImpactMedium); if (ground.GetComponent <PlatformController>() != null) { ground.GetComponent <PlatformController>().CallJiggle(); } } ballPhysics.ApplyPhysics(transform); }
/// <summary> /// We are detecting the ground and calculating offset variables for our stretch and squash function /// /// The original Stretch and Squash function has a hardcoded ground position of 0 at Y axis, /// so we need an offset for our ground to do the right calculations, because our ground is not always at 0. /// </summary> private void FixedUpdate() { if (disabled) { return; } collisionDetection.CastRayCast(); /* Since we are applying gravity constantly with our own physics, * we want to check if raycast hit anything, then we set the velocity.y back to 0, * so our ball don't fall through the platform. * We don't want to set velocity.y to 0 when bouncing, or else the ball won't bounce */ ballPhysics.ApplyVerticalCollision(collisionDetection); if (collisionDetection.collidedObject != null) // If our raycast system detects something { ground = collisionDetection.collidedObject.transform; // Set the ground variable to the detected gameobject if (ground != null) { groundBallLastTouched = ground.gameObject; } } // If raycast hits something, we want the ball to bounce up if (collisionDetection.hasCollided) { //bounce our ball ballBounce.Bounce(ref ballPhysics.velocity); //Phone haptic feedback HapticFeedback.Generate(UIFeedbackType.ImpactMedium); //if the platform we're hitting is a brick if (ground.GetComponent <PlatformController>() != null) { //Jiggle the brick ground.GetComponent <PlatformController>().CallJiggle(); if (ground.GetComponent <WinLevel>()) { ground.GetComponent <WinLevel>().TryWinGame(); } //if not we will raise the events that we need to if (ground.GetComponent <VictoryTag>() == null) { onNormalPlatformImpact.Raise(); onPlatformImpact.Raise(); } } } //ApplyPhysics recieves a transform and applies the final velocity vector which moves the ball ballPhysics.ApplyPhysics(transform); }
public void CryFace() { // HideFaces(); GameManager.instance.OnFailureEvent(); GameManager.instance.gameOver = true; isDead = true; DOTween.KillAll(); GameManager.instance.OnGameOver(); HapticFeedback.Generate(UIFeedbackType.Error); int rand = Random.Range(0, 2); GameManager.instance.PlaySound(rand == 1 ? GameManager.instance.missmatch01 : GameManager.instance.missmatch02); StartCoroutine(GameManager.instance.IncreaseXp()); }
// public void public void HappyFace() { // CamShake(); GameManager.instance.CalculateXP(); if (isClose) { if (!GameManager.instance.godMode) { //HideFaces(); GameManager.instance.OnCloseCallEvent(); GameManager.instance.PlaySound(closeSound); if (!popUpFreez && !popUpShield) { Bonus.OnScore("Close one !!"); } else { popUpFreez = false; popUpShield = false; } Instantiate(GameManager.instance.coinPrefab); // Instantiate(GameManager.instance.ExplodeParticle); score += 100; //GameManager.instance.AddCoins(); GameManager.instance.IncrementCharge(); GameManager.instance.PlaySound(GameManager.instance.progressBar, 0.2f); StartCoroutine(GameManager.instance.IncrementCoin(50)); if (GameManager.instance.vibration && !GameManager.instance.powerSaver) { // Handheld.Vibrate(); //StartCoroutine(Vibrate()); HapticFeedback.Generate(UIFeedbackType.ImpactHeavy); } //CamShake(); } else { StartCoroutine(GameManager.instance.IncrementCoin(5)); } } else { if (!GameManager.instance.godMode) { if (!popUpFreez && !popUpShield) { Bonus.OnScore("+50"); } else { popUpFreez = false; popUpShield = false; } score += 50; Instantiate(GameManager.instance.ExplodeParticle); if (GameManager.instance.vibration && !GameManager.instance.powerSaver) { HapticFeedback.Generate(UIFeedbackType.ImpactLight); // StartCoroutine(Vibrate()); } } } GameManager.instance.PlaySound(GameManager.instance.matchsound); //Invoke("MehFace", 1.2f); ScoreTxt.transform.DOScale(Vector3.one * 0.15f, 0.2f).OnComplete(() => { ScoreTxt.transform.DOScale(Vector3.one, 0.1f); }); ScoreTxt.text = score.ToString(); if (score > 1500 && !enlargedScreen1) { PlayerPrefs.SetInt("Crossed0", PlayerPrefs.GetInt("Crossed0", 0) + 1); //enlargedScreen1 = true; GameManager.instance.EnlargeScreen(); } if (score > 3000 && !enlargedScreen2) { PlayerPrefs.SetInt("Crossed1", PlayerPrefs.GetInt("Crossed1", 0) + 1); enlargedScreen2 = true; GameManager.instance.EnlargeScreen2(); } if (score > 5000 && !frenzy1) { PlayerPrefs.SetInt("Crossed1", PlayerPrefs.GetInt("Crossed1", 0) + 1); frenzy1 = true; GameManager.instance.Frenzy(); } if (score > 7500 && !frenzy2) { PlayerPrefs.SetInt("Crossed1", PlayerPrefs.GetInt("Crossed1", 0) + 1); frenzy2 = true; GameManager.instance.Frenzy2(); } for (int i = 0; i < stageScoreLimit.Length; i++) { if (score < stageScoreLimit[i]) { float tempScore = score; float stageScore = stageScoreLimit[i]; if (i != 0) { tempScore -= stageScoreLimit[i - 1]; stageScore -= stageScoreLimit[i - 1]; } else { tempScore = score; stageScore = stageScoreLimit[i]; } float percent = tempScore / stageScoreLimit[i]; for (int j = 0; j < timeGapControllers.Count; j++) { if (timeGapControllers[j].PositionNumber == i) { GameManager.instance.TimeGap = timeGapControllers[j].initialSpeed - ((timeGapControllers[j].initialSpeed - timeGapControllers[j].endSpeed) * percent); return; } } } } }