Search Unity

OnMouseDown functions not working after deactivating raycasts start in collider

Discussion in '2D' started by Allz, Jun 30, 2016.

  1. Allz

    Allz

    Joined:
    Mar 22, 2015
    Posts:
    2
    I went into the project settings -> Physics 2d and disabled Raycasts start in collider option because the the raycast shooting from my player object is blocked by the player's box collider. It seemed to work now and the raycast that shoots out from the player is detecting walls and enemies but all the functions relating to OnMouseDown is broken, OnMouseOver, OnMouseExit, OnMouseEnter. Anyone has any idea what is wrong?
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    There are other ways to prevent your raycast from hitting your player's collider.

    You can pass a Raycast a LayerMask to use for the raycast. So put your player on a special layer, and have his raycast look for the layers for walls and enemies.

    If you give your Player a "public LayerMask variableName;", you can choose the layers in the inspector, then pass that layermask to the Raycast2D method and it will only hit colliders on those layers.
     
    vakabaka likes this.