Unity Crashing when time slows
I'm participating in a Game Jam and made a Time Slow Powerup for the game. It was working, untill I added some new code and started crashing. The problem is, even after commenting it out, it still crashed. You should know that I am using Unity 2019.4.17f1.
This is the Time Slow code:
void Items() { if(Input.GetKeyDown(KeyCode.T) && timeRecharged) { timeCanCancel = false;
StartCoroutine(TimeSlow());
while (timeIsSlow)
{
if (Input.GetKeyUp(KeyCode.T))
{
timeCanCancel = true;
}
if (Input.GetKeyDown(KeyCode.T) && timeCanCancel)
{
StopCoroutine(TimeSlow());
Time.timeScale = 1f;
timeIsSlow = false;
StartCoroutine(TimeCancel());
}
}
}
}
IEnumerator TimeSlow()
{
timeRecharged = false;
Time.timeScale = timeSlowAmount;
timeIsSlow = true;
yield return new WaitForSeconds(4f);
Time.timeScale = 1f;
timeIsSlow = false;
yield return new WaitForSeconds(7f);
timeRecharged = true;
}
IEnumerator TimeCancel()
{
yield return new WaitForSeconds(4f);
timeRecharged = true;
}
HI again! New problem: how the hell those this:
if (Input.GetKeyDown(KeyCode.G)) { Physics2D.gravity = new Vector3(0, gravityStrength, 0); }
...crash unity?
Update: Calling items in FixedUpdate and changing gravityStrength to -gravityStrength fixed the problem with the gravity, but even so, the original problem has not been fixed.
Answer by GoldenShadow7 · Mar 26, 2021 at 03:19 PM
PS: Now i've got another bit of code that crashes unity:
if (Input.GetKeyDown(KeyCode.G)) { Physics2D.gravity = new Vector3(0, -gravityStrength, 0); }
....Note that i'm calling Items in FixedUpdate()
Your answer
![](https://koobas.hobune.stream/wayback/20220613031331im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
android app crashes for no logical reason 0 Answers
Help! My game keeps crashing on startup! 0 Answers
Android App Crashes Randomly 0 Answers
Timeline causes IOS app to crash when adding it, how do i fix this/ 0 Answers
Unity Editor constantly crashing 0 Answers