Principle
Single Responsibility
Each class should only do one thing. Avoid doing more than one (1) responsibility. If a class is for a the movement of a character, avoid including the handling of inputs.
Example
Instead of
public class MainCharacter() {
public void Walk(Vector2 direction, float speed) {
// Do walking
}
private void Update() {
// Detect controller inputs
// Call Walk(...);
}
}
Do this
/* MainCharacter.cs */
public class MainCharacter() {
public void Walk(Vector2 direction, float speed) {
// Do walking
}
}
/* MainCharacterInputHandler.cs */
public class MainCharacterInputHandler() {
[SerializeField]
private MainCharacter mainCharacter;
public void Update() {
// Detect controller inputs
// Call mainCharacter.Walk(...)
}
}