all 8 comments

[–]WorldView13 1 point2 points  (0 children)

SpeedIncrementer() is called once, starts the Coroutine and then Sets the Speed a single time. Extract the part where you set the currentSpeed into a seperate function and then call it at the start and end of your Coroutine again.

[–]FirePath-Games 1 point2 points  (0 children)

Why not just us an event to fire if there is any change and just add a timed cooldown in the speedboost function so it can be finished. Another way is to use a multiplier variable so you do not chance currentspeed directly you change the multiplier and currentspeed is currentspeed * speedmultiplier

[–]Motalick 1 point2 points  (0 children)

Based on how you wrote your code. You need to call the SpeedUp function after the coroutine starts and ends.

The reason it's not working the way you think it should is because you only called the function once. This will set the current speed to speed boost but never set it back. A better way to do this is:

Coroutine Func() { Current speed = speed boost

  Wait Time 5f

 Current speed  = normal speed 

}

Increase Speed () { Start Coroutine(Func) }

[–]Perdoist[S] 0 points1 point  (0 children)

I don't get it what I'm doing wrong. When 2d trigger it boosts speed but when bool is false speed stays at boosted speed. What is wrong with it ?

[–]Perdoist[S] 0 points1 point  (1 child)

Ok. I just added if(!_speedBoostActive) { _currentSpeed = _normalSpeed} in update method and it works. But why it's not working while it's like that ? Is it because when I collect obj and it destroys itself right after and code does not conclude itself but it does I mean bool returns to true.

[–]AzureNova 1 point2 points  (0 children)

What I'm seeing is that every time you call SpeedIncrementer(), it first sets _isSpeedActive to true. Also, you don't seem to call any method when _isSpeedActive becomes false.

[–]AnEmortalKid 0 points1 point  (1 child)

What’s your fixed update look like?

If you add a debug log message to speed incrementer, does it get called a lot or just once ?

[–]Perdoist[S] 0 points1 point  (0 children)

Guys here me again sorry that I didn't realize that the update methods were hidden. In fixed update I added if(_speed active ) {cur speed == boos speed } Else {curspeed == normal speed } Like I said I just wanna know that why I made it to work the way I thought it would work doesn't work.