- Home /
[Solved] How do use same code in single-player AND multi-player?
This question is solved. But I can't close this question...("closing question" requires 50 karma?)
Hi all. I created a multi-player TPS game.
First plan, the game was ONLY multi-player, But currently the game needs single-player. (campaign mode)
For this reason, my game's C# code is depend on unity networking. How do use same code in single-player AND multi-player? If it is not possible, How do fix my code?
My stupid plan is...
void Shot() {
networkView.RPC("RpcShot", RPCMode.All);
}
[RPC]
void RpcShot() {
Instantiate(prefabBullet);
}
Fix this code to...
void Shot() {
if (WrapNetwork.isMultiPlayer) {
networkView.RPC("RpcShot", RPCMode.All);
}else{
RpcShot();
}
}
[RPC]
void RpcShot() {
Instantiate(prefabBullet);
}
Nothing is wrong with your code. Do you get any errors?
No errors. But my stupid plan causes increase amount of code..
:How do fix my code?", nothing is broken, so nothing can be fixed. If you are asking for a better method, that an entirely different question altogether.
I would just write a function that wraps what you already have there. If you only want to pass in a string you will need to learn how to do reflection, but it shouldn't be too hard ;)
Sorry, my question is really wrong...
I looked C# reflection documents. It's hard, slow, messy...
Deter$$anonymous$$ed to use "my stupid plan". Solved! Thanks.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Network.isServer / isClient not working 1 Answer
'NetworkTranformChild' problem 1 Answer
[UNET] NetworkTransform - Synch Rotation - none - error 0 Answers