Created
April 1, 2019 14:16
-
-
Save pr00thmatic/9ca4f3e1abcc8a28bf1d9959b0d00736 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class Corutinas : MonoBehaviour { | |
public string state = "normal"; | |
public float duration = 1.5f; | |
public float acceleration = 2; | |
public float speedBoost = 0; | |
public float _timeInPowerup = 0; | |
public bool _boosting = false; | |
Coroutine c = null; | |
void Update () { | |
if (Input.GetKeyDown(KeyCode.Space) && !_boosting) { | |
this.StartCoroutine(PowerUpBehaviour()); | |
} | |
_timeInPowerup += Time.deltaTime; | |
} | |
IEnumerator Pausa () { | |
yield return new WaitForSeconds(Random.Range(0, 3f)); | |
} | |
IEnumerator PowerUpBehaviour () { | |
float timeWhileBoosted = 0; | |
_timeInPowerup = 0; | |
_boosting = true; | |
state = "fast"; | |
yield return StartCoroutine(Pausa()); | |
while (timeWhileBoosted < duration) { | |
speedBoost += acceleration * Time.deltaTime; | |
timeWhileBoosted += Time.deltaTime; | |
yield return null; | |
} | |
speedBoost = 0; | |
_boosting = false; | |
state = "normal"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment