Search Unity

(2D/JS) How to change the direction of a Raycast

Discussion in 'Scripting' started by Silverriolu295, Nov 26, 2014.

  1. Silverriolu295

    Silverriolu295

    Joined:
    Nov 12, 2014
    Posts:
    48
    I am a bit of a noob at this....

    I want to set it so if a variable is set to something, then the raycast will shoot left. If the variable is something else, it will shoot right.
    How do i do this? I've tried making another raycast like this:
    var hit2: RaycastHit2D = Physics2D.Raycast(transform.position, Vector2.right,distance,layerMask); {
    //stuff here
    }
    But then the raycast doesn't work at all!
    Help please!