- Home /
Decrement with --
Hello, So I'm new to unity and I was watching some tutorials. I used this code on double jumping by Blackthornprod in youtube.
if (Input.GetKeyDown("space") && extraJumps > 0)
     {
         extraJumps--;
         rigidbody.velocity = Vector2.up * jumpForce;
         PlayerAnimator.SetBool("isJumping", true);
         CreateDust();
         Debug.Log("Triggered");
     }
It's working on my part but I don't really understand it. My question is,
- why does the variable extraJumps only decrement on the second time I jump? When I hit the space twice, the "Triggered" logs twice but the decrement only executes once. 
- As an additional problem, my isJumping bool only sets to true on the second jump as well. 
- When I add conditions in this particular if statements like && isDodging == false && isGrounded == true the second jump doesn't work anymore 
I'm sorry if this is stupid but please help me. Thank you!!!
Answer by LilGames · Apr 28, 2021 at 04:38 PM
Because your extraJumps variable is surely being changed elsewhere in your code.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                