Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted how can i check if a variable is true or false

Discussion in 'Visual Scripting' started by xiarox123, Mar 24, 2021.

  1. xiarox123

    xiarox123

    Joined:
    Jan 4, 2020
    Posts:
    1
    how can i make that when bool variable is true or false this or that happens
    please help
     
  2. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    4
    Code (CSharp):
    1. if (A && B)
    2.         {
    3.             //stuff to do if  A and B are true
    4.         }
    5.  
    6. if (!A || !B)
    7.         {
    8.             //stuff to do if either A or B are false
    9.         }
    10.  
     
    psychomunky likes this.
  3. psychomunky

    psychomunky

    Joined:
    Feb 17, 2021
    Posts:
    44
    urumizawa has answered your question if you want multiple bools being checked for a single statement. If you only want one, we just adjust a little.

    Code (CSharp):
    1. public bool isActive = false;
    2.  
    3. void Update()
    4. {
    5.       // Here we check if isActive is true and if it is...
    6.       if (isActive)
    7.               {
    8.                      // ...then we do stuff here
    9.               }
    10.      // Since a bool can only be two values we use the else statement to do anything we want if it's false
    11.       else
    12.               {
    13.                       // Do stuff here
    14.               }
    15. }
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    113
    The better question is why people are giving C# answers in Unity Visual Scripting subforum.
     
  5. psychomunky

    psychomunky

    Joined:
    Feb 17, 2021
    Posts:
    44
    Oops. I have been in a different world recently. At any rate, you'll want to right click, add variable type bool, then add a compare script and attach the bool to the bool node at the bottom of that and the true or false to their corresponding actions, and connect the input node to whatever you want to trigger that compare action.

    EDIT -- you'll want to insert a "Toggle" function to change that bool btw.
     
unityunity