I have 2 objects both have box colliders,
Object A is parent to Object B
Both have scripts
Object A Script executes fine (Update() contents being executed ok)
Object B’s script consisting of an OnMouseDown() function won’t execute!
works fine when not a child just won’t execute when its a child.
It sounds like you’ve created a compound collider. I don’t think OnMouse events are called on subcolliders (just like OnCollision events aren’t). Those scripts have to go on object A in this case, and will be triggered whenever you click down over object A or object B’s collider.
To get around this, you could cast a ray from the camera at the point you clicked and use RaycastHit.collider to determine if you clicked on the right thing.
It would look like this (attached to object B):
if( Input.GetButtonDown("Fire1") ) {
var hit : RaycastHit;
if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), hit ) hit.collider == collider ) dosomestuff...
}
Absolutely spot on, this confirms what I suspected.
Not a problem I had started thinking I’d have to take my code up a level to the parent object and do something not too different to that.
Perfect.
I must say, this is by far a MOST EXCELLENT engine, I’ve tinkered with tge,dark blitz basic and a few others, but this is incredible. Even if I end up being let down on performance (Which at the moment doesn’t look like it’ll happen) its still a most excellent tool to prototype in.