title: Still pausing/resuming and start a new game is not working good. Can'r figure what should I do?
body: <p>First a screenshot of my Hierarchy :</p>
  
  <p>Everything is inside a one scene name The :</p>
  
  <p>The game start when Main Game is disabled. Inside Main Game sit all the game objects. The Main Menu and Game Manager are enabled.</p>
  
  <p>When running the game first time, When the game start there is short animation of the player for 5 seconds. The player start from some rotating degrees on Z. Z = 50 when x and y both are 0. Then the player is rotating slowly over the Z to 0.</p>
  
  <p>It's like the player is sleeping and awake up.
  I'm using post processing stack by unity.</p>
  
  <p>And here is the first problem. While the player is rotating on the Z and post processing effect is working if I press the Escape key it will bring me back to the Main Menu but then if I press the Escape key again it will start the game over again from the begin.</p>
  
  <p>But if I'm waiting in my game for the player to finish rotating on the Z and the post processing effect is finished and then pressing on Escape it will bring the main menu and second time will resume the game from the same point.</p>
  
  <p>I can't figure out why when the player is rotating and the post process is working the escape key make it start the game over again from the being ?</p>
  
  <p><a href="https://i.stack.imgur.com/Da0tV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Da0tV.jpg" alt="Hierarchy"></a></p>
  
  <p>This is a screenshot of the game when start and after finish the rotating and the process stack :</p>
  
  <p><a href="https://i.stack.imgur.com/oOCxN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oOCxN.jpg" alt="On the left when the game start cutscene on the right starting a conversation"></a></p>
  
  <p>Another problem I noticed now. After the game start using the post process and the player rotating finished if I press Escape it will go to main menu and escape again will be back to the game but for example in the second screenshot the conversation is not continue. It will return to the same point in the game but things not seems to continue like the conversation.</p>
  
  <p>On the Back to main menu object I have a script attached to it :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.SceneManagement;
  
  public class BackToMainMenu : MonoBehaviour
  {
      private bool _isInMainMenu = false;
      public GameObject mainGame;
      public GameObject mainMenu;
  
      void Update()
      {
          if (Input.GetKeyDown(KeyCode.Escape))
          {
              if (!_isInMainMenu)
              {
                  // -- Code to freeze the game
                  mainGame.SetActive(false);
                  mainMenu.SetActive(true);
              }
              else
              {
                  // -- Code to unfreeze the game
                  mainGame.SetActive(true);
                  mainMenu.SetActive(false);
              }
  
              _isInMainMenu = !_isInMainMenu;
          }
      }
  }
  </code></pre>
  
  <p>On the Main Menu object under Main Menu I have attached this script :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.SceneManagement;
  
  public class MainMenu : MonoBehaviour
  {
      public GameObject mainGame;
      public GameObject mainMenu;
  
      public void PlayGame()
      {
          mainGame.SetActive(true);
          mainMenu.SetActive(false);
      }
  
      public void QuitGame()
      {
          Application.Quit();
      }
  }
  </code></pre>
  
  <p>On the PLAY button I'm using this script method PlayGame from the MainMenu script.</p>
  
  <p>In the Main Game object on the Player object attached to thew Player I have some scripts the controller :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerController : MonoBehaviour
  {
      public float speed = 10.0f;
  
      // Update is called once per frame
      void Update()
      {
          float translatioin = Input.GetAxis("Vertical") * speed;
          float straffe = Input.GetAxis("Horizontal") * speed;
          translatioin *= Time.deltaTime;
          straffe *= Time.deltaTime;
  
          transform.Translate(straffe, 0, translatioin);
      }
  }
  </code></pre>
  
  <p>Player Lock Manager :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerLockManager : MonoBehaviour
  {
      public PlayerCameraMouseLook playerCameraMouseLook;
      public PlayerController playerController;
  
      // Start is called before the first frame update
      public void PlayerLockState(bool LockPlayer, bool LockPlayerCamera)
      {
          if (LockPlayer == true)
          {
              playerController.enabled = false;
          }
          else
          {
              playerController.enabled = true;
          }
  
          if (LockPlayerCamera == true)
          {
              playerCameraMouseLook.enabled = false;
          }
          else
          {
              playerCameraMouseLook.enabled = true;
          }
      }
  }
  </code></pre>
  
  <p>And Mouse Lock State :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class MouseLockState : MonoBehaviour
  {
      public bool lockState = true;
  
      private void Start()
      {
          LockState(lockState);
      }
  
      private void Update()
      {
  
      }
  
      public void LockState(bool lockState)
      {
          if (lockState == false)
          {
              Cursor.visible = true;
              Cursor.lockState = CursorLockMode.None;
          }
          else
          {
              Cursor.visible = false;
              Cursor.lockState = CursorLockMode.Locked;
          }
      }
  }
  </code></pre>
  
  <p>Under the Player as child I have the Player Camera object and attached to the Player Camera also some scripts :</p>
  
  <p>Player Camera Mouse Look :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerCameraMouseLook : MonoBehaviour
  {
      public float sensitivity = 5.0f;
      public float smoothing = 2.0f;
  
      private GameObject player;
      private Vector2 mouseLook;
      private Vector2 smoothV;
  
      // Use this for initialization
      void Start()
      {
          player = this.transform.parent.gameObject;
      }
  
      // Update is called once per frame
      void Update()
      {
          var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
  
          md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
          smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
          smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
          mouseLook += smoothV;
  
          mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);
  
          transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
          player.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, Vector3.up);
      }
  }
  </code></pre>
  
  <p>And Depth Of Field script :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.PostProcessing;
  
  public class DepthOfField : MonoBehaviour
  {
      public GameObject player;
      public PostProcessingProfile postProcessingProfile;
      public bool dephOfFieldFinished = false;
      public PlayerLockManager playerLockManager;
  
      private Animator playerAnimator;
      private float clipLength;
  
      // Start is called before the first frame update
      void Start()
      {
          playerAnimator = player.GetComponent&lt;Animator&gt;();
  
          AnimationClip[] clips = playerAnimator.runtimeAnimatorController.animationClips;
          foreach (AnimationClip clip in clips)
          {
              clipLength = clip.length;
          }
  
          var depthOfField = postProcessingProfile.depthOfField.settings;
          depthOfField.focalLength = 300;
          StartCoroutine(changeValueOverTime(depthOfField.focalLength, 1, clipLength));
          postProcessingProfile.depthOfField.settings = depthOfField;
      }
  
      IEnumerator changeValueOverTime(float fromVal, float toVal, float duration)
      {
          playerLockManager.PlayerLockState(true, true);
  
          float counter = 0f;
  
          while (counter &lt; duration)
          {
              var dof = postProcessingProfile.depthOfField.settings;
  
              if (Time.timeScale == 0)
                  counter += Time.unscaledDeltaTime;
              else
                  counter += Time.deltaTime;
  
              float val = Mathf.Lerp(fromVal, toVal, counter / duration);
  
              dof.focalLength = val;
              postProcessingProfile.depthOfField.settings = dof;
  
              yield return null;
          }
  
          playerAnimator.enabled = false;
          dephOfFieldFinished = true;
      }
  }
  </code></pre>
  
  <p>I have under Main Game also a object name Openning Scene and attached to it :</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class OpeningCutscene : MonoBehaviour
  {
      public NaviConversations naviConversation;
      public DepthOfField dephOfField;
  
      // Update is called once per frame
      void Update()
      {
          if (dephOfField.dephOfFieldFinished == true)
          {
              naviConversation.PlayNaviConversation(0);
              dephOfField.dephOfFieldFinished = false;
          }
      }
  }
  </code></pre>
  
  <p>It's a bit long but everything is connected.</p>
  
  <ol>
  <li><p>The game start with the main menu.</p></li>
  <li><p>When clicking the PLAY button a new game start.</p></li>
  <li><p>When a new game start the script Depth Of Field is in action using the post processing. Also I'm locking the player so the player will not be able to move either the mouse or the player it self.</p></li>
  <li><p>When the depth of field script finished his work a conversation between Navi and the Player start. When a conversation is in action the player can move the mouse 360 degrees but cant move the player to any direction.</p></li>
  <li><p>When the conversation ended the player can also move to any direction.</p></li>
  </ol>
  
  <p>Problems :</p>
  
  <ol>
  <li><p>When start a new game while the depth of field script is in work pressing escape will bring the main menu but pressing escape again will not resume the depth of field script but will start it all over again.</p></li>
  <li><p>When waiting the conversation to end if not pressing escape until the conversation ended then when moving around and pressing escape it will bring the main menu and again will resume the game from the same point.</p></li>
  <li><p>The problems is when the game is doing something like the depth of field it will start the game over again instead resuming or when in conversation in the middle the conversation will never continue.</p></li>
  <li><p>The ides with the escape key is once to get to main menu and second to resume the game. </p></li>
  <li><p>The PLAY button is what should only start a new game and not the escape key.</p></li>
  </ol>
  
  <p>It's a bit long but everything is connected.</p>