Search Unity

Difficulty with three bool && statment

Discussion in 'Visual Scripting' started by superwholock, May 8, 2021.

  1. superwholock

    superwholock

    Joined:
    Feb 6, 2018
    Posts:
    6
    Im going crazy with this one, and I feel kinda dumb for not being able to figure it out

    Once my three bool variables are set to false, I'd like a function to execute, at this point I'm just trying to say something in the console.

    I'm using OnPointerClick, and using the IPointerClickHandler and UnityEngine.EventSystems, just not included in this snippet

    Code (CSharp):
    1. public void OnPointerClick(PointerEventData pointerEventData)
    2.     {
    3.         if (this.gameObject.tag == "Thyme")
    4.         {
    5.             ThymeImage.gameObject.SetActive(false);
    6.             Thyme = false;
    7.             Debug.Log("Clicked on Thyme");
    8.             Debug.Log("Thyme Bool " + Thyme);
    9.         }
    10.         if (this.gameObject.tag == "Parsley")
    11.         {
    12.             ParsleyImage.gameObject.SetActive(false);
    13.             Parsley = false;
    14.             Debug.Log("Clicked on parsley");
    15.             Debug.Log("Parsley Bool " +Parsley);
    16.         }
    17.         if (this.gameObject.tag == "RedPepper")
    18.         {
    19.             PepperFlakesImage.gameObject.SetActive(false);
    20.             RedPepper = false;
    21.             Debug.Log("Clicked on redpepper");
    22.             Debug.Log("Red Pepper Bool " + RedPepper);
    23.         }
    24.     }
    this code outputs three false bools like I'd hoped, except whenever I try to write an if statement that only activates when all three are false, It won't work

    Code (CSharp):
    1. void Update()
    2.     {
    3.         if((Thyme == false) && (Parsley ==false) && (RedPepper == false))
    4.         {
    5.             Debug.Log("all Spices ARE COLLECTED PLEASE WORK OH GOD");
    6.         }
    7.     }
    This code never outputs the "all spices collected" message

    I've also tried the shorthand version of the above snippet which uses !Thyme, etc instead of Thyme == false, AND I've also tried using the .activeSelf function, which works for two of them, but the last one clicked never returns false for some reason

    Code (CSharp):
    1. if ((PepperFlakesImage.gameObject.activeSelf == false) && (ParsleyImage.gameObject.activeSelf == false)
    2.             && (ThymeImage.gameObject.activeSelf == false))
    3.         {
    4.             Debug.Log("all spices have been collected, F*** yes");
    5.         }
    my console currently only outputs the debug statements in the OnPointerClick function