OnMouseDown() cube face?

OnMouseDown() will tell me when an object is clicked. Is there a way to know which face of a cube was touched?

You'll need to cast a ray from the mouse position into the scene, and examine the RaycastHit result to check which triangle was hit. There are two triangles on each side of a cube, so you'll need to check for both triangles for each side.


function OnMouseDown() {
    var hit : RaycastHit;
    if (Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit))
        print("Hit triangle index: "+hit.triangleIndex);

You'll need to work out which indices relate to which sides, and group them accordingly in to "if" statements, like this:

        if (hit.triangleIndex == 0 || hit.triangleIndex == 1) {
            print ("You hit the top!");

0 and 1 might not be the top, I haven't tested this myself - this is just for illustration!

Good luck!