Search Unity

Is There A Reason This Code Is Making MY Game Crash

Discussion in 'Scripting' started by DotArt, Sep 23, 2022.

  1. DotArt

    DotArt

    Joined:
    Jun 12, 2021
    Posts:
    82
    Hey, so i have a toggle button for if you want to set quest goal complete pops to be active and im using the code like this

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class ToggleQuestUpdates : MonoBehaviour
    7. {
    8.    public Toggle toggle;
    9.  
    10.     void Start()
    11.     {
    12.         toggle.isOn = QuestComeIn.QuestUpdates;
    13.     }
    14.  
    15.     public void Switch()
    16.     {
    17.         if(toggle.isOn == true)
    18.         {
    19.             toggle.isOn = false;
    20.             QuestComeIn.QuestUpdates = false;
    21.  
    22.         }
    23.         else
    24.         {
    25.             toggle.isOn = true;
    26.             QuestComeIn.QuestUpdates = true;
    27.         }
    28.     }
    29. }
    i have the bool in another script as thats where all the other things are related to the quest and they all get saved together.

    I have the function called on value changed and when i click it in game it crashes
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    JeffDUnity3D and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Amazing catch Praetor... seems like every non-trivial event-driven system always ends up with this same old rotten fishy "code smell."
     
  4. DotArt

    DotArt

    Joined:
    Jun 12, 2021
    Posts:
    82
    PraetorBlue likes this.