Hey guys.
My game is a 2d platformer RPG, which combat system is mainly sword. In order to detect targets inside a certain space, a lot of Physics2D.Overlapxxxall are used.
As the title said, when I play my game in unity, unity takes more than 20% of my CPU capacity to run when there are multiple enemies in the scene. When I don’t play my game, it just only takes less than 1%. My CPU is Intel i7-4770 3.40GHz.
Is overuse of overlapxxxall the reason for such thing happening? How can I fix it?
I appreciate your help.
I will provide my project copy later.
Have a look at your profiler. Window > Analysis > Profiler. Change the dropdown from Timeline to Hierarchy. Run the game for a bit, stop, click on the graph, and expand the trees. Post a screenshot here and we might be able to work out what kind of thing is draining CPU.
Also, make sure to delete any Debug.Logs that are repeating every frame.