Last active
November 17, 2021 02:35
-
-
Save curious-username/329c1116c166bb2e9ec338cd70dc62d2 to your computer and use it in GitHub Desktop.
slowdown implimentation
This file contains 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
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