RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
Debug.Log("Hit");
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
Debug.Log("No Hit");
}
RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
Debug.Log("Did Hit");
}
RaycastHit hit;
/*
(Vector3) hit.point - the point where the ray has collided.
(Quaternion) hit.normal - the normal of the GameObject the ray has collided.
(float) hit.distance - the distance between the ray origin and hit.point.
(Transform) hit.transform - the transform of the GameObject the ray has hit
(Rigidbody) hit.rigidbody - rigidbody attached to GameObject ray collided,
if no rigidbody is attached, value is null.
(Vector2) hit.textureCoord - the coordinate of the point on the texture
of the GameObject the ray collided.
*/
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up);
Ray ray = new Ray(position, direction);
RaycastHit hit2;
if (Physics.Raycast(ray, out hit2, maxStepDistance))
{
reflDirection = Vector3.Reflect(direction, hit2.normal);
hitPosition = hit2.point;
}
else
{
position += reflDirection * maxStepDistance;
}
Debug.DrawRay(hitPosition, reflDirection, Color.green);
RaycastHit target;
float raydistance = 50;
Debug.DrawRay(beamorigin.position, transform.forward*raydistance, Color.yellow);
if (Physics.Raycast(beamorigin.position, transform.forward*raydistance, out target, raydistance, targetlayer))
{
Debug.Log(target.collider.tag);
}