Question by
unity_71ADB8E90F3C02D1CCFE · Jun 11, 2021 at 07:59 PM ·
crashunityeditorloop
While loop crashing all the time with breaks,While loop crashing constantly
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?
Comment
Your answer
Follow this Question
Related Questions
Unity Project friert ein (OnPlayMode) 0 Answers
Unity crashes when using while loop 0 Answers
Package Manager Error 1 Answer
unity crashes every time when i want to open the editor 0 Answers
Unity Crash Problem 0 Answers