- Home /
How to avoid duplicating code between MonoBehaviour and NetworkBehaviour?
Hello, I'm working on a game with both a local and networked level, and so I've got a local and networked version of the same script, with very similar functionality. I'd like to deduplicate some of this code so I don't have to update both scripts whenever there's a change. However, the networked one must extend NetworkBehaviour, so I can't just make a base class for both of them without it also extending NetworkBehaviour, and when I tried this it broke the local version. Composition (adding the base class as local field of the two classes) doesn't seem like a good fit, since some of the shared methods modify the object itself, specifically its position. I imagine this is an issue other people have run into as well. What's the best way to fix it? Is there a way to have the local version also extend NetworkBehaviour but disable the networked aspects of it? Thanks
Your answer
