Skip to content

Commit

Permalink
Added small internal cooldown to the PlayLandParticlesAction StateAct…
Browse files Browse the repository at this point in the history
…ion (#260)

* Added small internal cooldown to PlayLandParticlesAction StateAction

https://open.codecks.io/unity-open-project-1/decks/15-code/card/18k-avoid-spamming-particles-on-sliding

Whenever the PlayLandParticlesAction StateAction is exited by the state machine, it checks if total elapsed time is greater then the total elapsed time of the last particle call + a small amount.

If so, only then do we tell the DustParticle Controller to play, and we also set the new time to beat to be the current time.

* Update PlayLandParticlesActionSO.cs

Removed the unnecessarily verbose extra function

Co-authored-by: Ciro Continisio <ciro@unity3d.com>
  • Loading branch information
MTrecozzi and ciro-unity committed Dec 12, 2020
1 parent 9179940 commit 4ffdc82
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ public class PlayLandParticlesAction : StateAction
//Component references
private DustParticlesController _dustController;

private float _coolDown = 0.3f;
private float t = 0f;

public override void Awake(StateMachine stateMachine)
{
_dustController = stateMachine.GetComponent<DustParticlesController>();
}

public override void OnStateExit()
{
_dustController.PlayLandParticles();
if (Time.time >= t + _coolDown)
{
_dustController.PlayLandParticles();
t = Time.time;
}
}

public override void OnUpdate() { }
}

0 comments on commit 4ffdc82

Please sign in to comment.