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. Dismiss Notice

box casting

Discussion in 'Documentation' started by NAVIDabc, Jul 7, 2022.

  1. NAVIDabc


    Feb 20, 2021
    hello im new in unity , i want to set 2 layer mask for boxcast but i dont know how , like i want to say if the player collider was touching ground and wall layer collider the player is grounded
    || and && didnt work in this case ,can anyone help?

    Code (CSharp):
    1.     private bool isGrounded()
    2.     {
    3.         RaycastHit2D raycast = Physics2D.BoxCast(, collider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
    4.         return raycast.collider != null;
    5.     }
  2. CharlesWard


    Unity Technologies

    Apr 19, 2017
    Use the bitwise logic operators (single | and &) in this case, not the Boolean operators (double || and &&). The bitwise operators operate on each single digit in the binary number. They are often used with values that are treated as masks or flags.

    See for an example of how to add an additional layer to a layer mask.