I would like to know if there are any preferred way of determining which script to put the OnTrigger codes in.
Example. Object A, if collides with Object B then Object B transforms.
Should i have code in Object A script’s to detect tag of B and transform B there, or
should I have code in Object B detecting object A and transform myself?
Any preferred way or does it matter on type of code access I need for the scenario? Thanks
I’m not sure there is a Golden rule here and it mainly comes down to preference based on the situation.
I tend to put the method onto the object that owns the intended action.
For example, if I had an object that represented some lava, the action would be to burn or damage the health of anything that enters it. Instead of attaching this behaviour to every character in my scene, I would place it only once on the lava. Each character might have a Health component that the lava would interact with.
If I had an object that needed to push something, I would put the method on the pushers side, rather than the object that gets pushed.
Ok that actually makes perfect sense, my situation is only one instance of the objects. For one to many it would make sense, but overall I think your rule makes sense and to make my stuff consistent I will follow it.