Skip to content

Instantly share code, notes, and snippets.

@curious-username
Last active November 17, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curious-username/329c1116c166bb2e9ec338cd70dc62d2 to your computer and use it in GitHub Desktop.
Save curious-username/329c1116c166bb2e9ec338cd70dc62d2 to your computer and use it in GitHub Desktop.
slowdown implimentation
private bool _isSlowDownActive = false;
[SerializeField]
private GameObject _slowDown;
[SerializeField]
AudioSource _slowDownSound;
private WaitForSeconds _fiveSecondsYieldTime = new WaitForSeconds(5.0f);
private WaitForSeconds _twoSecondsYieldTime = new WaitForSeconds(2.0f);
void CalculateMovement()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontalInput, verticalInput, 0);
if (_isSpeedUpActive || _isBoostActive)
{
transform.Translate(direction * (_speed * _speedMultiplier * Time.deltaTime));
}
else if(_isSlowDownActive)
{
transform.Translate(direction * (_speed * Time.deltaTime / _speedMultiplier));
}
else
{
transform.Translate(direction * (_speed * Time.deltaTime));
}
public void SlowDown()
{
_isSlowDownActive = true;
_slowDownSound.Play();
_slowDown.SetActive(true);
StartCoroutine(TurnOffSlowDown());
}
IEnumerator TurnOffSlowDown()
{
yield return _fiveSecondsYieldTime;
_isSlowDownActive = false;
_slowDown.SetActive(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment