Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Debug.Log("Collided with " + hit.collider.name); }
Ray ray = new Ray(transform.position, transform.forward); float rayLength = 100f; Debug.DrawLine(ray.origin, ray.origin + ray.direction * rayLength, Color.red);Overall, the UnityEngine Ray class is a powerful tool for game developers and is part of the very popular Unity engine.