void OnCollisionStay2D(Collision2D col) { float x = 0; if (StartGame && StartGameCountdownEnded) { x = getAcceleration(); } rb.velocity = Vector2.zero; player_min_pos = Player.transform.localPosition; if (col.gameObject.tag == "jumpblock") { rb.velocity = Vector2.zero; rb.AddForce(new Vector2(20 * x, 40f), ForceMode2D.Impulse); } else if (col.gameObject.tag == "toggle") { Break_Sound.Play(); rb.velocity = Vector2.zero; rb.AddForce(new Vector2(20 * x, 20f), ForceMode2D.Impulse); } else if (col.gameObject.tag == "trap") { } else { rb.velocity = Vector2.zero; rb.AddForce(new Vector2(20 * x, 20f), ForceMode2D.Impulse); } }
void OnCollisionEnter2D(Collision2D col) { rb.drag = 0; player_min_pos = Player.transform.localPosition; float x = 0; Player.GetComponent <Animator>().SetBool("isPlayerDownTrigger", false); Player.GetComponent <Animator>().SetBool("isPlayerDown", false); Player.GetComponent <Animator>().SetBool("isPlayerUp", true); if (StartGame && StartGameCountdownEnded) { x = getAcceleration(); } if (col.gameObject.tag == "jumpblock") { Player.GetComponent <Animator>().SetTrigger("isPlayerJump"); col.gameObject.GetComponent <Animator>().SetTrigger("MushroomJump"); Mushroom_Sound.Play(); rb.AddForce(new Vector2(rb.velocity.x, 40f), ForceMode2D.Impulse); } else if (col.gameObject.tag == "toggle") { Break_Sound.Play(); rb.velocity = Vector2.zero; rb.AddForce(new Vector2(20 * x, 20f), ForceMode2D.Impulse); } else if (col.gameObject.tag == "startblock") { if (StartGameCountdownEnded) { for (int i = 0; i < GenerateBlocks.BlockList.Count; i++) { GenerateBlocks.BlockList[i].SetActive(true); } for (int i = 0; i < GenerateBlocks.CarrotList.Count; i++) { GenerateBlocks.CarrotList[i].SetActive(true); } StartGameScript.ins.Countdown.text = "Go!"; StartGameScript.Top_Panel.SetActive(true); StartGame = true; } } else if (col.gameObject.tag == "trap") { StartCoroutine(CameraShake.CamShake.Camera_Shake()); Game_Sound.Stop(); Ouch_Sound.Play(); Player.transform.localPosition = new Vector2(0, Player.transform.localPosition.y); StartGame = false; GameOver(); } else { Grass_Sound.Play(); rb.velocity = Vector2.zero; rb.AddForce(new Vector2(20 * x, 20f), ForceMode2D.Impulse); } }