Search Unity

  1. 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

Raycast selection

Discussion in '2D' started by sirjacobgoodrich, Nov 10, 2019.

  1. sirjacobgoodrich


    Jul 27, 2019
    So im working on a 2d rts, and I need to be able to select units, I have a layer for selectables, and I am trying to make it call a function that sets selection to true for whatever unit I click on, I ONLY want things in the selectables layer to be able to be hit. here is my script :

  2. LiterallyJeff


    Jan 21, 2015
    In the future, please paste your code with codetags in the forums instead of uploading a screenshot. It's much easier to read and copy/paste if necessary.

    You've clearly got some errors going on. You're on the right track, but you should try to understand what those errors mean, and read the docs for the functions you're using so you can provide the function with the values that it is expecting.

    1 - You're missing a closing curly brace for your first if statement.
    2 - Physics2D.Raycast does not return a bool, so you can't use it as the condition for a control block.
    3 - No overload for Physics2D.Raycast accepts a Ray parameter.
    4 - No overload for Physics2D.Raycast accepts an "out RaycastHit2D" parameter

    Check out the documentation for Physics2D.Raycast