Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Spacebar/Jumping is causing me problems

Discussion in 'Scripting' started by GamesOnAcid, Aug 24, 2016.

  1. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    I have asked this question before, but none of the solutions worked. I've poked around the troubled scripts and some other parts of my game for a week or so, and I've still not found a way to fix the problem. I cannot spot my error or tell why Unity is doing what it is doing.

    For starters, I have 3 scripts:
    • A tablet/smartphone
    • A Camera app
    • A flashlight app
    The tablet is supposed to store all the applications that I will make for it (i.e. the camera and flashlight) The bug comes in when I actually run the game. I can open and close the tablet and click the buttons on it to trigger the applications, but for some reason, when I bump into certain objects or jump (especially jump) things trigger on and off for no reason at all. For example, if I enable my flashlight with the button in the tablet, I close the tablet, and begin to jump, each jump will turn the flashlight on and off, respectively. Here are the scripts that they are running off of.

    The tablet
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Tablet : MonoBehaviour {
    6.  
    7.     public Canvas canvas; //Declaring the canvas object
    8.     public Image tablet, cameraicon, flashlighticon, messageicon, remindersicon, settingsicon; //Declaring the canvas images
    9.     public bool tabletIsEnabled; //Declaring boolean to identify if the tablet is active
    10.  
    11.     void Start() {
    12.         #region disablers
    13.         tablet.enabled = false;
    14.         cameraicon.enabled = false;
    15.         flashlighticon.enabled = false;
    16.         messageicon.enabled = false;
    17.         remindersicon.enabled = false;
    18.         settingsicon.enabled = false;
    19.         #endregion //Region to disable the images
    20.         tabletIsEnabled = false; //Tablet is not enabled
    21.     }
    22.  
    23.     public void ToggleTablet() {
    24.         #region enablers
    25.         tablet.enabled = true;
    26.         cameraicon.enabled = true;
    27.         flashlighticon.enabled = true;
    28.         messageicon.enabled = true;
    29.         remindersicon.enabled = true;
    30.         settingsicon.enabled = true;
    31.         #endregion //Region to enable the images
    32.         tabletIsEnabled = true; //Tablet is enabled
    33.         Time.timeScale = 0.0f; //Pauses the time in-game; Stops frame updating
    34.     }
    35.  
    36.     public void UntoggleTablet() {
    37.         #region disablers
    38.         tablet.enabled = false;
    39.         cameraicon.enabled = false;
    40.         flashlighticon.enabled = false;
    41.         messageicon.enabled = false;
    42.         remindersicon.enabled = false;
    43.         settingsicon.enabled = false;
    44.         #endregion //Region to disable the images
    45.         tabletIsEnabled = false;
    46.         Time.timeScale = 1.0f; //Unpauses the time in-game; Turns on frame updating
    47.     }
    48.  
    49.     void Update() {
    50.         if (Input.GetKeyDown (KeyCode.I) && tabletIsEnabled == false) { //Conditional statement to toggle the tablet method
    51.             ToggleTablet ();
    52.         } else if (Input.GetKeyDown (KeyCode.I) && tabletIsEnabled == true) { //Other part of the statement untoggling the tablet
    53.             UntoggleTablet ();
    54.         }
    55.     }
    56. }
    57.  
    The camera
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class CameraApp : MonoBehaviour {
    6.  
    7.     public Image cameraoverlay; //Declaring images on the canvas
    8.     public Tablet tabletReference; //Reference to the tablet script
    9.     public bool cameraIsEnabled; //Declaring boolean to tell if the camera is on or off
    10.  
    11.     void Start() {
    12.         tabletReference = GameObject.Find ("Tablet (Player)").GetComponent<Tablet> (); //Finding the instance of the tablet
    13.         cameraoverlay.enabled = false; //Disabling the overlay
    14.         cameraIsEnabled = false; //And the camera is not on
    15.     }
    16.  
    17.     public void ToggleCameraApp() { //Public method for the camera button in-game
    18.         if (cameraIsEnabled == false) { //Checks the state of the camera
    19.             cameraoverlay.enabled = true; //Turns on the overlay
    20.             tabletReference.UntoggleTablet (); //Untoggles the tablet through the Tablet script
    21.             cameraIsEnabled = true; //Tells the game the camera is on
    22.         }
    23.     }
    24.  
    25.     void Update() {
    26.         if (Input.GetKeyDown (KeyCode.I) && cameraIsEnabled == true) { //Checks for keypress 'I' and if the camera is on...
    27.             cameraoverlay.enabled = false; //Turn off the overlay
    28.             cameraIsEnabled = false; //Disable the camera
    29.         }
    30.     }
    31. }
    32.  
    The flashlight
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FlashlightApp : MonoBehaviour {
    5.  
    6.     public Light flashlight;
    7.     public Tablet tabletReference;
    8.     public bool flashlightIsEnabled;
    9.  
    10.     void Start() {
    11.         tabletReference = GameObject.Find ("Tablet (Player)").GetComponent<Tablet> ();
    12.         flashlightIsEnabled = false;
    13.         flashlight = GameObject.Find ("Flashlight").GetComponent<Light> ();
    14.         flashlight.intensity = 0;
    15.     }
    16.  
    17.     public void ToggleFlashlight() {
    18.         if (flashlightIsEnabled == false) {
    19.             flashlight.intensity = 1;
    20.             tabletReference.UntoggleTablet ();
    21.             flashlightIsEnabled = true;
    22.         }
    23.     }
    24.  
    25.     void Update() {
    26.         if(Input.GetKeyDown (KeyCode.I) && flashlightIsEnabled == true) {
    27.             flashlight.intensity = 0;
    28.             flashlightIsEnabled = false;
    29.         }
    30.     }
    31. }
    32.  
    Note (If any of these matter): I am using the default FPSController for the player. The scripts are all attached to one GameObject, and it is a child of the FirstPersonCharacter, which is a child of the FPSController. The canvas the images are printed on is not a child of anything.

    If anyone can help me out even a tiny bit, please let me know. This is really putting a burden on me as I cannot progress on the game until this is fixed. Thanks for reading, and let me know if you find anything.

    EDIT: If the commenting on the code makes it too hard to read, let me know and I'll remove it. I'm submitting this project for school and it needs to be commented enough so that an idiot could understand it. I wouldn't normally over-comment it like I did :p
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    so you thought reposting the thread afresh without making any mention of what you're tried so far so we can go over the same ground as before is going to help?


    what scripts on those objects have OnCollision / OnTrigger functions?
    you don't appear to be using the input manager's virtual buttons/axis so have you search your project for instance of "Keycode.Space"?
     
    Last edited: Aug 24, 2016
  3. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    The commenting is fine, and other than the difference in opinion on what a toggle is (yours are more "enablers" and "disablers" separately), the only thing I can spot is overlapping state changes all triggered separately by the same event (pressing "I" on the keyboard). You should really just use one input controller for this whole thing and have all of these scripts register as listeners to the various events it generates. That way, you can see logic problems or areas where input will overlap really easy, and deal with them all in one place. In this case, the flashlight/camera turning off at the same time the tablet is made active is likely intentional, but if and when the logic gets any more complicated (for instance, if you put in a delay/animation to activate the light using a coroutine), then this is going to get difficult to manage in different places like this.

    I can't see here anything like the problem you're talking about, so either it's an inspector value somewhere, a different script entirely, or I'm just thick (definitely possible!). Hope you figure it out, though.
     
    lloydsummers likes this.
  4. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    1) The only change recommended was to check for other instances of the flashlight script I didn't know about, which there were none.
    2) The collision doesn't matter, it occurs with all colliders in my game
    3) Unless the default FirstPerson script uses KeyCode.Space, it doesn't exist. I wouldn't use that in any of my scripts.
     
  5. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    OK,

    A couple things to mention.. You are using the same input methods for all three objects, and generally speaking, creating the same "Structure" for all three objets, just with different terminology.

    The best way to do that, is inheritence. You create a base class they derive from, abstract away the variable names so "flashlight.gameObject" becomes "element.gameObject" and usually assign an enum object type for identification.

    That said, then you only use the code once.

    The problem I see, is you have three different objects, listening to the same keypresses of I. So, if you press I, all three objects could try to open or close at once.

    I have a lot of suggestions, structure wise, to keep your code modular and flexible. But, nothing above shows the Space key for jump anywhere.

    I'd recommend starting to build your code like this though...

    ElementManager > <List>ElementController -> <List>Elements

    So, you could have a TabletController -> with { FlashlightElement, WhateverElement }. If that is the heiarchy you want. Or an InventoryController -> { TabletElement, FlashglihtElement, WhateverElement } if you want. But right now, you have three different objects looking for the same input presses that could get very challenging if you go to say 15 tablets, and 100 sub objects down the line ... If the Tablet is in charge of the application, put it in charge. It should then be dictating who is working and when...
     
  6. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    I'll try this and see if it fixes the problem, thanks
     
  7. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    Ok, so I moved EVERYTHING to just one script and now it looks like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Tablet : MonoBehaviour {
    6.  
    7.     public Canvas canvas; //Declaring the canvas object
    8.     public Image tablet, cameraicon, flashlighticon, messageicon, remindersicon, settingsicon, cameraoverlay; //Declaring the canvas images
    9.     public bool tabletIsEnabled, cameraIsEnabled, flashlightIsEnabled; //Declaring boolean to identify if certain apps are active
    10.     public Light flashlight; //Declaring the light variable
    11.  
    12.     void Start() {
    13.         #region disablers
    14.         tablet.enabled = false;
    15.         cameraicon.enabled = false;
    16.         flashlighticon.enabled = false;
    17.         messageicon.enabled = false;
    18.         remindersicon.enabled = false;
    19.         settingsicon.enabled = false;
    20.         cameraoverlay.enabled = false;
    21.         #endregion //Region to disable the images
    22.         tabletIsEnabled = false; //Tablet is not enabled
    23.         cameraIsEnabled = false;
    24.         flashlightIsEnabled = false;
    25.         flashlight = GameObject.Find ("Flashlight").GetComponent<Light> (); //Sets the flashlight to the light instance in-game
    26.         flashlight.intensity = 0; //Turns off the flashlight
    27.     }
    28.  
    29.     public void ToggleTablet() {
    30.         #region enablers
    31.         tablet.enabled = true;
    32.         cameraicon.enabled = true;
    33.         flashlighticon.enabled = true;
    34.         messageicon.enabled = true;
    35.         remindersicon.enabled = true;
    36.         settingsicon.enabled = true;
    37.         #endregion //Region to enable the images
    38.         tabletIsEnabled = true; //Tablet is enabled
    39.         Time.timeScale = 0.0f; //Pauses the time in-game; Stops frame updating
    40.     }
    41.  
    42.     public void UntoggleTablet() {
    43.         #region disablers
    44.         tablet.enabled = false;
    45.         cameraicon.enabled = false;
    46.         flashlighticon.enabled = false;
    47.         messageicon.enabled = false;
    48.         remindersicon.enabled = false;
    49.         settingsicon.enabled = false;
    50.         #endregion //Region to disable the images
    51.         tabletIsEnabled = false;
    52.         Time.timeScale = 1.0f; //Unpauses the time in-game; Turns on frame updating
    53.     }
    54.  
    55.     public void ToggleCamera() { //Public method for the camera button in-game
    56.         if (cameraIsEnabled == false) { //Checks the state of the camera
    57.             cameraoverlay.enabled = true; //Turns on the overlay
    58.             UntoggleTablet (); //Untoggles the tablet through the Tablet script
    59.             cameraIsEnabled = true; //Tells the game the camera is on
    60.         }
    61.     }
    62.  
    63.     public void ToggleFlashlight() { //Public method for the flashlight button in-game
    64.         if (flashlightIsEnabled == false) { //Checks for the flashlight state
    65.             flashlight.intensity = 1; //Turns the flashlight on
    66.             UntoggleTablet ();
    67.             flashlightIsEnabled = true; //Tells the game the flashlight is on
    68.         }
    69.     }
    70.  
    71.     void Update() {
    72.         if (Input.GetKeyDown (KeyCode.I) && tabletIsEnabled == false) { //Conditional statement to toggle the tablet method
    73.             ToggleTablet ();
    74.         } else if (Input.GetKeyDown (KeyCode.I) && tabletIsEnabled == true) { //Other part of the statement untoggling the tablet
    75.             UntoggleTablet ();
    76.         }
    77.         if (Input.GetKeyDown (KeyCode.I) && cameraIsEnabled == true) { //Checks for keypress 'I' and if the camera is on...
    78.             cameraoverlay.enabled = false; //Turn off the overlay
    79.             cameraIsEnabled = false; //Disable the camera
    80.         }
    81.         if(Input.GetKeyDown (KeyCode.I) && flashlightIsEnabled == true) {
    82.             flashlight.intensity = 0; //Turn off the flashlight
    83.             flashlightIsEnabled = false; //Disable the flashlight
    84.         }
    85.     }
    86. }
    87.  
    Here's what I can tell you after I've done all this:
    • I haven't been able to replicate the glitch where colliding with other objects triggers the camera overlay or light.
    • I have been able to replicate the jump glitch
    I have not 100% confirmed the pattern I think I am seeing, but it appears that:
    • The last selected button that I choose is the one that is triggered when I jump
    • The booleans for isCameraEnabled and isFlashlightEnabled trigger to 'true' when I jump, respectively enabling depending on what one was last selected
    • It only occurs once, then it stops until another button is selected, and it repeats.
    If you couldn't tell, I really need this fixed, so I would be willing to provide whatever evidence/footage you may need to help me solve this problem. Let me know what else you guys see, thanks!
     
  8. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    What a mess. With everything public it must be a nightmare to debug. I suggest making private everything related to your flashlight and see which part of code will raise an exception.
     
  9. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    Also mono/vs debugging is your friend, you really need to find out who's changing your public fields. Also need to spy on every method capable of changing those fields.
     
  10. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    Ok, I'll poke around Mono's debugging tools and see what I can find. Other than that, the only things I believe I can change in terms of the publicity of the variables/methods are the ToggleTablet/UntoggleTablet, as the other ones need to be accessed by a button.
     
  11. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    I looked around the debugging, and it appears that there are no errors in any of my code. I also don't believe that any of the methods I have are changing during the runtime process. All I know is that I haven't made progress on fixing the problem. If anyone knows anything about debugging that I could use effectively, or if anyone knows of something I could do to fix the problem I am having, let me know. I'll check back in the morning as I'm off to bed shortly.
     
  12. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    You have to give me a few minutes, its taking a long time to rework the all the code ...
     
  13. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    So, don't be disheartened. There is a lot to learn, and even more to do it "right".

    First, I just want to add, this code has NO jumping in it. Nothing what so ever, and we can't fix the problem without getting all the code. Because, to be honest, I don't know what you are using for a jump button / where it is being called, or any of those details. But the problem, technically, isn't the code above.

    However ... here is a way of simplifing your code:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5.  
    6. public class Tablet : MonoBehaviour
    7. {
    8.  
    9.     public Canvas canvas; //Declaring the canvas object
    10.  
    11.     [SerializeField]
    12.     public List<Image> CanvasImages = new List<Image>(); //Declaring the canvas images
    13.     public Image cameraoverlay;
    14.     public Light flashlight; //Declaring the light variable
    15.  
    16.     public enum ActiveStates
    17.     {
    18.         Tablet,
    19.         Flashlight,
    20.         Camera,
    21.         None
    22.     }
    23.  
    24.     public ActiveStates ActiveState = ActiveStates.None;
    25.  
    26.     void Start()
    27.     {
    28.         foreach (var image in CanvasImages)
    29.             image.enabled = false;
    30.  
    31.         cameraoverlay.enabled = false;
    32.  
    33.         flashlight = GameObject.Find("Flashlight").GetComponent<Light>(); //Sets the flashlight to the light instance in-game
    34.         flashlight.intensity = 0; //Turns off the flashlight
    35.     }
    36.  
    37.     public void ToggleTablet(bool state)
    38.     {
    39.         foreach (var image in CanvasImages)
    40.             image.enabled = state;
    41.  
    42.         if (state)
    43.             Time.timeScale = 0.0f;
    44.         else
    45.             Time.timeScale = 1.0f;
    46.     }
    47.  
    48.     public void ToggleCamera(bool state)
    49.     {
    50.             cameraoverlay.enabled = state;
    51.     }
    52.  
    53.     public void ToggleFlashlight(bool state)
    54.     {
    55.         if (state)
    56.             flashlight.intensity = 1;
    57.         else
    58.             flashlight.intensity = 0;
    59.     }
    60.  
    61.     void Update()
    62.     {
    63.         if (!Input.GetKeyDown(KeyCode.I))
    64.             return;
    65.  
    66.         switch (ActiveState)
    67.         {
    68.             case ActiveStates.Tablet:
    69.                 // turn off tablet
    70.                 ToggleTablet(false);
    71.                 break;
    72.             case ActiveStates.Flashlight:
    73.                 ToggleFlashlight(false);
    74.                 // turn off flashlight
    75.                 break;
    76.             case ActiveStates.Camera:
    77.                 // turn off camera
    78.                 ToggleCamera(false);
    79.                 break;
    80.             case ActiveStates.None:            
    81.                 ToggleTablet(true);
    82.                 break;
    83.         }
    84.     }
    85. }
    86.  
    87.  
    However, that isn't really enough

    When I mentioned earlier, you should be using inheritance, this is what I mean ...

    An element register, so all your inventory "Registers" somewhere you can access it.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5.  
    6. /// <summary>
    7. /// You can use this to get access to any elements you've registered in your scene (and check any value you've stored in ItemElement class)
    8. /// </summary>
    9. public static class ItemRegistry
    10. {
    11.  
    12.     private static List<ItemElement> _itemElements = new List<ItemElement>();
    13.  
    14.     /// <summary>
    15.     /// Add an element to the registry
    16.     /// </summary>
    17.     /// <param name="element"></param>
    18.     public static void RegisterElement(ItemElement element)
    19.     {
    20.         if (!_itemElements.Contains(element))
    21.         {
    22.             _itemElements.Add(element);
    23.             Debug.Log("ItemRegistry:RegisterElement > Adding " + element.ElementType.ToString());
    24.         }
    25.     }
    26.  
    27.     /// <summary>
    28.     /// Remove an element to the registry
    29.     /// </summary>
    30.     /// <param name="element"></param>
    31.     public static void UnRegisterElement(ItemElement element)
    32.     {
    33.         if (_itemElements.Contains(element))
    34.         {
    35.             _itemElements.Remove(element);
    36.             Debug.Log("ItemRegistry:UnRegisterElement > Removing " + element.ElementType.ToString());
    37.         }
    38.     }
    39.  
    40.     /// <summary>
    41.     /// Get element from the registry, may be null
    42.     /// </summary>
    43.     /// <param name="element"></param>
    44.     public static ItemElement GetElement(ItemElement.ElementTypes ElementType)
    45.     {
    46.         var element = _itemElements.FirstOrDefault(x => x.ElementType == ElementType);
    47.         return element;
    48.     }
    49.  
    50.     /// <summary>
    51.     /// Print all elements in the registry
    52.     /// </summary>
    53.     public static void PrintElements()
    54.     {
    55.         foreach (var element in _itemElements)
    56.             Debug.Log("ItemRegistry::PrintElements > " + element.ElementType.ToString());
    57.     }
    58. }
    59.  
    Then a base class for all your elements to derive from, specify an icon for toggling them on and off, and follow a common input method...

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class ItemElement : MonoBehaviour {
    5.  
    6.     public enum ElementTypes
    7.     {
    8.         Tablet,
    9.         Flashlight,
    10.         Camera,
    11.         None
    12.     }
    13.  
    14.     // What element are we?
    15.     public ElementTypes ElementType = ElementTypes.None;
    16.     //Where is our icon?
    17.     public Image ElementIcon;
    18.     // Where is the canvas?
    19.     public Canvas ElementCanvas;
    20.     // What keycode do we need?
    21.     public KeyCode ActivationCode = KeyCode.I;
    22.     // Is this item enabled?
    23.     public bool IsElementActive = false;
    24.     // Is there a dependency on a parent object being active?
    25.     public ItemElement Dependency;
    26.  
    27.     // Setup our canvas
    28.     public virtual void Start()
    29.     {
    30.         // Is the canvas null?  It is faster to assign this through the Editor.
    31.         if (ElementCanvas == null) // Then lets hunt down a replacement
    32.             ElementCanvas = FindObjectOfType<Canvas>();
    33.     }
    34.  
    35.     public virtual void OnEnable()
    36.     {
    37.         // Register ourselves
    38.         ItemRegistry.RegisterElement(this);
    39.     }
    40.  
    41.     public virtual void OnDisable()
    42.     {
    43.         // Unregister ourselves
    44.         ItemRegistry.UnRegisterElement(this);
    45.     }
    46.  
    47.     public virtual void Update()
    48.     {
    49.         if (Input.GetKeyDown(ActivationCode))
    50.             ElementSelected();
    51.     }
    52.  
    53.     // Check if the dependency is met or not required, and toggle the state
    54.     public virtual void ElementSelected()
    55.     {
    56.         if (Dependency != null && !Dependency.IsElementActive)
    57.             return;
    58.  
    59.         ToggleState();
    60.         ElementChanged();
    61.     }
    62.  
    63.     /// <summary>
    64.     /// Toggles the input
    65.     /// </summary>
    66.     private void ToggleState()
    67.     {
    68.         IsElementActive = !IsElementActive;
    69.  
    70.         if (ElementIcon != null)
    71.             ElementIcon.enabled = IsElementActive;
    72.     }
    73.  
    74.     #region Called by Parent Class
    75.     // Do we require a dependency?  Must be called by parent class
    76.     public void CheckAddDependency(ElementTypes type)
    77.     {
    78.         if (Dependency == null)
    79.             Dependency = ItemRegistry.GetElement(type);
    80.     }
    81.  
    82.     /// <summary>
    83.     /// The state changed.  Must be called by parent class
    84.     /// </summary>
    85.     public virtual void ElementChanged()
    86.     {
    87.  
    88.     }
    89.  
    90.     #endregion
    91. }
    92.  
    Then finally, you can create a simple way of adding and removing objects just by extending the class...

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class ItemCamera : ItemElement
    6. {
    7.     public new ElementTypes ElementType = ElementTypes.Camera;
    8.  
    9.     public Image CameraOverlay;
    10.  
    11.     // If the element is selected, take a moment to check the depdency
    12.     public override void ElementSelected()
    13.     {
    14.         CheckAddDependency(ElementTypes.Tablet); // <-- this means the item "won't work" unless the tablet is open
    15.         base.ElementSelected();
    16.     }
    17.  
    18.     public override void ElementChanged()
    19.     {
    20.         // OK, so the dependency check passed, and the object state has changed.
    21.         CameraOverlay.enabled = IsElementActive;
    22.     }
    23. }
    24.  
    So now, to add anything new in the future, you just have to add a couple of lines...

    Anyway, I digress, but the code you shared, doesn't contain the problem directly, just points to a greater set of issues that you will have a hard time debugging.
     
  14. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    283
    Understandable, I'll look into make a more efficient way of making what I want. If the problem still persists for some reason, I'll report back in a new question, as it'll take me a while to soak in all this new information. Thank you all for the help