Search Unity

Slow down time multiple hits mess (Solved)

Discussion in 'Scripting' started by filiphdan, Sep 22, 2017.

  1. filiphdan

    filiphdan

    Joined:
    Aug 15, 2017
    Posts:
    14
    Hello,

    im new to unity but already finishing my first game, very small basic project im doing for android OS, well i have a problem wen using the slow down time in player collision:

    IEnumerator OnCollisionEnter(Collision collisionInfo)
    {
    if (collisionInfo.collider.tag == "Obstacle")
    {
    Time.timeScale = 1f / slowDown;
    Time.fixedDeltaTime = Time.fixedDeltaTime / slowDown;
    yield return new WaitForSeconds (0.1f);
    Time.timeScale = 1f;
    Time.fixedDeltaTime = Time.fixedDeltaTime * slowDown;
    //FindObjectOfType<GameManager>().EndGame();
    }

    This works perfectly wen player colides with one objects but, if i hit another object wen this script is being performed unity will execute it again and it becames a mess.
    I just wanted to turn it off while it is acting with the first object it collided, i tryed with a bool variable but could not make it work, any ide on how to achieve this?

    Thanks!
     
  2. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Could you provide the example you tried with a boolean? I dont see how it wouldnt work with one?
     
    filiphdan likes this.
  3. filiphdan

    filiphdan

    Joined:
    Aug 15, 2017
    Posts:
    14
    I ended up solving it with a boolean :)

    But thanks Rob!