Hi, i have two way to show highlighted text (name of item) on the crosshair once i point the item
Method 1) Using raycast on update method , so raycast will work for each frame t o highlugh text on crosshair once i look to item (this time i will add only 1 script to the player for raycast)
Method 2) I will use onmouse over script for each item to do this. (thsi time i will need add the onmouseover script for all items)
So, what is the best way for it. I mean for performance purpose.
There probably isn’t going to be any change in performance in either case, so just go with the one that fits your workflow. I’d personally take Method1 for my sanity.
I would choose first. It’s always much more comfortable to manually check something, because you have more control over it. And one single raycast doesn’t matter for whole performance. They are pretty cheap.
I agree with what was said so far, and also find option 1 more convenient.
As a rule of thumb, ignore performance when developing. Especially as a beginner. The overwhelming majority of topics you may think about in terms of performance, wont ever have a measurable effect on the real world performance of your game. Such as this topic. And when you eventually stumble into an actual performance problem you can use Unitys’ profiler to identify and address it reactively.
Of course there are exceptions to these rules. There are certain topics that rely so heavily on certain optimizations, that they wont even run in realtime without approaching them correctly. However, these are usually highly advanced, or very specific, topics such as procedural generation, or heavy math number crunching, which you usually do not run into unknowingly.
When tackling such a topic you usually already know what kind of approach you need to chose and why - and if not you will quickly realise afterwards.
That said, you can develop most indie games without thinking about performance proactively even once. And if you eventually want to release the game, that’s exactly how you should approach performance. Otherwise you will waste a lot of time on things that will have absolutely zero impact, while probably still missing the topics that would actually have mattered.