I am just wondering what would be more efficient. Adding a script to an object with a OnMouseOver function that access a static variable, or using a raycast system with GetComponent? This is for a targeting system for my game. Static variable can be used in this instance.
Golden question, does it matter? The one thing I have been taught and stand by as a golden rule to development, if its not broke, don’t fix it.
I use a combination of both systems over a few projects and never noticed a problem with either. My gut would say that OnMouseOver will be a tad more optimised since its hooked to the engine and can benefit from performance gains on the C++ side but honestly its probably minute.
Just go with whichever system you are more comfortable/familiar with and don’t worry about micro-optimisations unless there is a problem.
Though as an FYI GetComponent will always be a bit slow, nothing major but I avoid it as a rule and pass references where possible instead.