Longtime listener, first time caller.
I have a 3d scene where I am casting a ray from the camera toward a 3d object that contains multiple materials (one per side). I want to return the material of the side that the ray hits.
My current script (below) returns the same material (“material.002”) regardless of where I click or if I rotate the gameObject to show a different material/side:
Ray ray1 = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit1;
if (Physics.Raycast(ray1, out hit1))
{
Material obj1Color = hit1.transform.gameObject.GetComponent().material;
Debug.Log(obj1Color);
}
Any help is appreciated.