Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to check "Void Start" when it has "Don't Destory" on Load?

Discussion in 'Scripting' started by RuneShiStorm, Mar 25, 2022.

  1. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    Hi all!
    I'm trying to make function that turns off the players "Skills" in a particular scene in my game.
    I tried this but It will only work if I play from the current scene. If I play the previous scene and the player enter the next scene (where the skills should turn off) it wont have any effect.

    Code (csharp):
    1.  
    2.  
    3.     {
    4.         if (SceneManager.GetActiveScene().name == mapScene)
    5.         {
    6.             canPunch1 = false;
    7.             canPunch2 = false;
    8.             canPunch3 = false;
    9.         }
    10.     }
    11.  
    12.  
    13.  
    I don't want to write this code in Void Update since it will call to many times thoughout the rest of the game..
    Any idea how do go about this?

    Cheers!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,523
    The 2D forum is for specific 2D related discussion. I'll move your post to the scripting forum.
     
    RuneShiStorm likes this.
  3. Trafulgoth

    Trafulgoth

    Joined:
    Jun 5, 2013
    Posts:
    45
    RuneShiStorm likes this.
  4. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    To anyone Who needs help in the fututre.
    I implemented this LATE in the game so the solution is very Noobish, but it works:

    Code (csharp):
    1.  
    2.         Scene currentScene = SceneManager.GetActiveScene();
    3.         string sceneName = currentScene.name;
    4.         //DisablePlayerController + Can Not Pause
    5.         if (sceneName == "SNStart")
    6.         {
    7.             _gm.canNotPauseState();
    8.             _thePlayer.DisableController();
    9.  
    10.         }
    11.         else
    12.         {
    13.             _gm.canPauseState();
    14.             _thePlayer.EnableController();
    15.         }
    16.  
    17.  
    18.  
    I added a public void in the Player Controller like:

    Code (csharp):
    1.  
    2.  
    3.     public void DisableController()
    4.     {
    5.         _characterController.GetComponent<PlayerController>().enabled = false;
    6.     }
    7.     public void EnableController()
    8.     {
    9.         _characterController.GetComponent<PlayerController>().enabled = true;
    10.     }
    11.  
    12.  
    13.  
    GameManager:

    Code (csharp):
    1.  
    2.  
    3.     public void canNotPauseState()
    4.     {
    5.         canPause = false;
    6.     }
    7.     public void canPauseState()
    8.     {
    9.         canPause = true;
    10.     }
    11.  
    12.  
    13.