I have an empty object with a script on it and I want to be able to move the empty over other objects and then have it print out the name of the material for the triangle that it's hovering above. (Its for something else, but I only need help getting to that stage, I can do the rest from that point). I found this on the topic but the answer is very vauge. I finished steps 1 and 2 but I can't figure out number 3. Here is my code so far...
void Update (){
Ray ray = new Ray(transform.position, new Vector3(0, -100, 0));
RaycastHit hit;
if(Physics.Raycast(ray, out hit)){
print ("Triangle Index: " + hit.triangleIndex);
Mesh mesh = hit.collider.gameObject.GetComponent<MeshFilter>().mesh;
print ("Submesh Count: " + mesh.subMeshCount);
}
}
Could someone show me how to finish it off so that when I move the empty over different objects, it would print out the name of the material per triangle?
Thanks, Matthew