public void Jump() { Vector2 movement = new Vector2(0, JumpForce); gameObject.GetComponent <Rigidbody2D>().AddForce(movement, ForceMode2D.Impulse); playerAudio.JumpUp(); }
public void ButtonDown(GameObject gameobject) { // How much force is applied to player for jump. JUMP_FACTOR = gameobject.GetComponent <ADSRManager>().GetJump(); // Checks whether Player is grounded. Grounded = gameobject.GetComponent <ADSRManager>().GetGrounded(); // Only jump if grounded. RB = gameobject.GetComponent <Rigidbody2D>(); playerAudio = gameobject.GetComponent <PlayerAudio>(); // Adding a force to simulate a jump. if (Grounded) { RB.AddForce(new Vector2(0.0f, JUMP_FACTOR), ForceMode2D.Impulse); playerAudio.JumpUp(); } }