Posted January 13, 2023 by hsquared
#Unity code timer
// This is how I added a 'Boost' in case the player stops too soon and needs to finish:
// In Unity PlayerController.cs:
void Start()
{
InvokeRepeating("Stalled", 5, 1); // The actual timer function.
}
// -------------------------
void Stalled()
{
timer--;
bBoost = true;
}
Update()
{
if (bBoost) // boost. Do a boost if the snowboarder is stalled (stuck) for more than 5 seconds.
{
surfaceEffector2D.speed = speed + 10f; // The Boost!
dustParticles.Play();
if (surfaceEffector2D.speed < 5f)
{
dustParticles.Stop();
}
bBoost = false;
}