Un Raycast lanza un rayo invisible y comprueba si golpea algo.
if (Physics.Raycast(
transform.position,
transform.forward,
5f))
{
Debug.Log("Golpeó algo");
}
if (Physics.Raycast(
transform.position,
transform.forward,
out RaycastHit hit,
5f))
{
Debug.Log(hit.collider.name);
}
hit.point
hit.normal
hit.distance
hit.collider
hit.transform
[SerializeField]
private LayerMask capas;
if (Physics.Raycast(
transform.position,
transform.forward,
out RaycastHit hit,
10f,
capas))
{
}
Debug.DrawRay(
transform.position,
transform.forward * 5f,
Color.red
);