Search Unity

Question Hacer que unity solo ejecute el codigo una vez // Make unity only run code once

Discussion in 'Editor & General Support' started by Alberto7YT, Aug 29, 2022.

  1. Alberto7YT

    Alberto7YT

    Joined:
    Apr 4, 2020
    Posts:
    2
    Hola,
    Tengo un script que comprueba si el usuario esta conectado a internet al abrir el juego, el problema es que esto lo hago en el menu principal entonces cada vez que el usuario vuelve al menu principal lo comprueba otra vez. Hay alguna forma de hacer que unity solo ejecute el script una vez al abrir el juego y cuando el usuario vuelva al menu principal otra vez ya no lo cargue?
    Gracias.

    //

    Hello,
    I have a script that checks if the user is connected to the internet when opening the game, the problem is that I do this in the main menu so every time the user returns to the main menu it checks it again. Is there a way to make unity only run the script once when opening the game and when the user returns to the main menu again it doesn't load it anymore?
    Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    You can set a static bool.

    Code (csharp):
    1. public static bool NetworkWasChecked;
    That will stay true until you restart the application. When you restart, it will be false and you can retry.

    OR...

    You could use PlayerPrefs, which will never again check no matter how much you run. I think you want the static method?