Question by
DaresFireson · Apr 07, 2019 at 03:08 PM ·
c#scripting problemfunctionscene-loading
[SOLVED]My code line don't execute
i have the following script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour {
public GameObject ui;
public SceneFader sceneFader;
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.P))
{
TogglePauseMenu();
}
}
public void TogglePauseMenu()
{
ui.SetActive(!ui.activeSelf);
if(ui.activeSelf)
{
Time.timeScale = 0f;
}
else
{
Time.timeScale = 1f;
}
}
public void Retry()
{
TogglePauseMenu();
sceneFader.FadeTo(SceneManager.GetActiveScene().name);
}
public void BackToMap()
{
Debug.Log("Back to Map");
sceneFader.FadeTo("ChoosingLevels");
}
}
The script is attached to a panel which get activated by a button. The problem is function BackToMap which is working if the panel is active at the beginning of the level. But when is set to inactive and activated by button, execute only the debug line. I have another script attached to another inactive panel with exactly the same function and there it work fine.
Comment
Best Answer
Answer by DaresFireson · Apr 24, 2019 at 08:28 AM
It seems I had to add:
Time.timeScale = 1f;
after loading scene code as I was pausing the game