rotating ray with player rotation.

What I am trying to achieve is to get a ray to follow the players global? rotation and face the direction the cube is at the moment it points the same direction even when the cube rotates ill show you the script

void Update () 
{   
    RaycastHit hit = new RaycastHit();

    Debug.DrawRay(transform.localPosition, Vector3.right * 10);

    if (Physics.Raycast(transform.position, Vector3.right, out hit, 10.0f))
    {
        Debug.Log(hit.transform.name);
    }
}

Use `transform.forward` instead of `Vector3.right` (assuming you want the ray to be cast in the object's z direction). `Vector3.right` is world space.

Here is the video about what you are looking for