When running this set of code and setting jumpType to 2, the game instantly crashed and forces me to close it through task manager. I have tried adding breaks into the while loop but it still doesn't work. Any ideas on a fix for this?
,> Code
if (isGrounded)
{
if (jumpType == 1)
{
if (Input.GetButton("Jump") && !jumpBlocked)
{
rb.AddForce(-jumpForce * rb.mass * Vector3.down);
jumpBlocked = true;
Invoke("UnblockJump", jumpCooldown);
}
}
if (jumpType == 2)
{
while (jumpCount != 2)
{
if (Input.GetButton("Jump") && !jumpBlocked)
{
rb.AddForce(-jumpForce * rb.mass * Vector3.down);
jumpBlocked = true;
Invoke("UnblockJump", jumpCooldown);
jumpCount = jumpCount + 1;
if (jumpCount == 2)
{
break;
}
}
}
}
if (jumpType == 3)
{
while (jumpCount != 3)
{
if (Input.GetButton("Jump") && !jumpBlocked)
{
rb.AddForce(-jumpForce * rb.mass * Vector3.down);
jumpBlocked = true;
Invoke("UnblockJump", jumpCooldown);
jumpCount = jumpCount + 1;
if (jumpCount == 3)
{
break;
}
}
}
}
// Ground controller
rb.velocity = Vector3.Lerp(rb.velocity, inputForce, changeInStageSpeed * Time.fixedDeltaTime);
}
When I switch to jump type 2 the unity engine will instantly crash and just doesn't respond. I've added breaks into the while loop but it still crashes. Any ideas?
↧