I have been playing with the mouse and attempting to rollover and hightlight various mesh within the scene. What seems weird is that when I use a mesh collider, I cannot get either the OnMouse or RayCastHit checks to work (box seems to work fine). I looked through the documentation a bit and saw nothing that would say it should matter on the type of collider I applied to the mesh. Some insight would be great here.
Secondly, I had 2 box colliders attached to two separate mesh in the scene (they are part of the same main object) but are not parent child to each other. When I applied the box collider to the element higher in the tree the lower element would not give me any event response but as soon as I removed the collider from the higher node the lower would respond as expected. I am not sure if this is me just doing something improperly or what. Again, these two nodes are at the same level and are not parent/child.
Thanks for the clarification and help. I believe you eluded to the issue which was the mesh in the mesh collider, I believe this wasn’t pointing to the proper place. I made the adjustment and it seems to be working properly now.
I have a very similar problem. I’m creating some objects completely within a script, and I can’t get them to behave the same way as objects I create in the GUI – even though they look identical. I don’t get OnMouseDown messages sent in the dymanically created case. My code looks something like this:
GameObject meshObject = new GameObject();
MeshFilter meshFilter = meshObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
MeshCollider meshCollider = meshObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
Renderer meshRenderer = meshObject.AddComponent("MeshRenderer") as Renderer;
meshObject.AddComponent("ClickCell"); // the OnMouseDown catching script
Mesh cellMesh = new Mesh();
meshFilter.mesh = cellMesh;
meshCollider.sharedMesh = cellMesh;
// Code to create cellMesh follows...
So, I’m most suspicious of the mesh itself (since that’s the only difference I can see from creating the object above in the UI). It renders correctly, and has normals assigned, but no tangents at the moment. Is there anything else that could be wrong with it?