Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

can i put an if inside an if

can i put an if inside an if

Best Answer

  • JIMMY_VASHI04JIMMY_VASHI04 Member
    Accepted Answer

    This is possible

    If(){
       If(){
          //ANYTHING
       }
    }
    


    This is not possible

    If(if())

Answers

  • Xx_korashi_xXXx_korashi_xX Member
    edited July 28

    yeah i tried before u answer an it worked but thx

  • It works, not only two if's, multiple if's. For example, if you pressed the F key, we are going to check if we have the flashlight (with a bool), and then checks if there is enough battery (with float battery). These are imported from UnityEngine namespace:


    public float battery;

    public bool haveFlashlight;

    void Update()

    {

    if (Input.GetKeyDown(KeyCode.F))

    {

    if (haveFlashlight)

    {

    if (battery is greater than 0, I cannot write it here because the text editor does some weird thing when I write the greater than symbol)

    {

    \\turn on flashlight

    }

    }

    }

    }

Sign In or Register to comment.