Jump delay??
I've searched the entire web to find a solution for this. I'm using a C# script and I can't get a jump delay. Here's the jump part of my script :
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (CanJump == true)
{
if (CanJump == true)
{
if (CanJump == true)
{
CanJump = false;
rigbody.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
Invoke("resetIsJumping", 3);
}
}
}
}
void resetIsJumping()
{
CanJump = true;
}
}
The triple if (CanJump == true) is unnecessary. Can you elaborate what's going wrong?
Examples:
If you can only jump once, the reset invoke is not working correctly.
If you want to automatically keep jumping every 3 seconds when holding down space, you should use Get$$anonymous$$ey ins$$anonymous$$d of Get$$anonymous$$eyDown, your boolean should prevent the frequency from beco$$anonymous$$g insane.
If you can't jump at all, you have to set CanJump to true in the Start() or Awake() function of your script, or simply set it in the inspector (if you're variable is public) or if it's private set its default value to true.
If you don't see a jump at all, you might want to test first with a Debug.Log() within the if-statement so you can see whether it works or not, if you do see that Debug, then perhaps the force you're applying is not strong enough or your rigidbody is locked or too heavy.
I hope that helps, if it doesn't, please elaborate by showing more code or images to give us a better idea of what you're trying to achieve. I'd be happy to help! :)
Answer by ElijahShadbolt · Nov 19, 2016 at 06:31 AM
Your script works fine for me. Maybe you need to make sure that when the game starts, CanJump is set to true. If it is set to false in any other way after the delay time, it will remain off.
For example, you could add this before the Update function:
void Awake()
{
CanJump = true;
}
Your answer
Follow this Question
Related Questions
Picking up an item and spawning a new one. 0 Answers
Is Random.InitState's Seed's random generated numbers change computer to computer? 0 Answers
Help with enemy AI Please! (on 2D Platformer) 0 Answers
Need help with adding ground detection to my jump. (c#) (3D) 1 Answer
player not able to double jump 0 Answers