Created
July 5, 2014 04:12
-
-
Save poemdexter/333293fe7aa56559de90 to your computer and use it in GitHub Desktop.
2D raycast for Unity3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position, direction, length, layerMask); | |
// check hit in direction | |
if (hit.collider != null) { | |
// we hit something check what it is | |
if (hit.collider.gameObject.CompareTag("wall")) { | |
// we hit a wall so don't translate in this direction | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment