Tutorial by Examples

This function casts a ray from point origin in direction direction of length maxDistance against all colliders in the scene. The function takes in the origin direction maxDistance and calculate if there is a collider in front of the GameObject. Physics.Raycast(origin, direction, maxDistance); F...
You can use raycasts to check if an ai can walk without falling off the edge of a level. using UnityEngine; public class Physics2dRaycast: MonoBehaviour { public LayerMask LineOfSightMask; void FixedUpdate() { RaycastHit2D hit = Physics2D.Raycas...
Having your scripts call Raycast directly may lead to problems if you need to change the collision matrices in the future, as you'll have to track down every LayerMask field to accommodate the changes. Depending on the size of your project, this may become a huge undertaking. Encapsulating Raycast ...

Page 1 of 1