Is it better to split a script into different scripts?
First, sorry for my english. Second, I want to know if splitting a script into many different scripts is fine. I have a player script which contains movement, attack, health but I would like to split that actions into different scripts like "PlayerHealth.cs", "PlayerAttack.cs", "PlayerJump", "PlayerMovement". I could have a PlayerController script and only use an update function because I've seen using mutiple update functions is not good for performance.
I'm asking this because I saw this blog: https://gamedevelopment.tutsplus.com/articles/unity-now-youre-thinking-with-components--gamedev-12492 and it says we should use a script for each characteristic.
So, the final result would be: PlayerController.cs > Health.cs, Attack.cs, etc.cs. I like this way because I could re-use scripts for different objects.
Thanks in advance.
Answer by FortisVenaliter · Oct 03, 2017 at 10:59 PM
There is no correct answer. It all comes down to which works better for your design. By all means, give it a shot. The best way to learn a technique's strengths and weaknesses are to try it yourself.
This is a very useful pattern in some circumstances, but in others, combining scripts can be better.
It ultimately comes down to your preferences, and the needs of the design.
Wow. I think you're right. I just "gave it a shot" and I like it. By the way, you said there is no correct answer but your answer helped me. Should I accept this answer as correct? I'm new on this site.