I’m spawning several dozens of same objects using prefab from a script. The prefab has its own script assigned, which uses OnMouseUp(), however only two or so objects from all those spawned actually get OnMouseUp called for.
I double checked that they all have mesh colliders assigned. What could the problem be? :\
Have you checked the docs about OnMouseUp? OnMouseUp only is called if the mouse pointer didn’t moved out of the collider or GUI element since the button was pressed. Could it be the problem? I mean: if the object is moving, you probably will loose it.
I personally prefer to use OnMouseOver - at least I’ve never had any problem with it:
function OnMouseOver(){
if (Input.GetMouseButtonUp(0)){
// do your stuff
}
}
Another problem: I’ve heard about strange errors with mesh colliders, like objects disappearing when near to frustum planes. The problem seems to be with their bounds being incorrectly generated by Unity - who knows if it could interfere with mouse-to-object relation? Try to use box colliders or whatever just to test this possibility.