public void TryJump() { if (!CheckGroundHandler.IsGrounded) { return; } if (!Inputs.Jump) { return; } CheckGroundHandler.Disable(new UnityTimer().SetAmount(1f)); AudioSource.PlayOneShot(Settings.JumpAudioClip); Rigidbody.AddForce(Vector3.up * Settings.JumpForce, ForceMode.Impulse); }
public void ShouldDisabledCheckForXTime() { var floor = new GameObject("floor"); floor.transform.position = new Vector3(0, 0, 0); var floorCol = floor.AddComponent <BoxCollider>(); floorCol.size = new Vector3(1, 1, 1); var groundedObject = new GameObject("groundedObject"); groundedObject.transform.position = new Vector3(0, 1.5f, 0); var objCol = groundedObject.AddComponent <CapsuleCollider>(); objCol.height = 2f; objCol.radius = 0.5f; var checkGroundHandler = new CheckGroundHandler(groundedObject.transform, 0.1f); checkGroundHandler.DebugMode(true).CheckGround(); Assert.True(checkGroundHandler.IsGrounded); var timerMock = new Mock <ITimer>(); checkGroundHandler.Disable(timerMock.Object); checkGroundHandler.CheckGround(); Assert.False(checkGroundHandler.IsGrounded); timerMock.SetupGet(t => t.Completed).Returns(true); Assert.False(checkGroundHandler.IsGrounded); checkGroundHandler.CheckGround(); Assert.True(checkGroundHandler.IsGrounded); Object.DestroyImmediate(floor); Object.DestroyImmediate(groundedObject); }