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. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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:
    56
    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,150
    JeffDUnity3D and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    28,187
    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:
    56
    PraetorBlue likes this.
unityunity