- Home /
Help for LAN multiplayer in C# ?
Hey guys
I'm almost finished my new game, and the only thing left to implement is the LAN multiplayer. I've found loads of great tutorials on this for JavaScript, but some of my game, such as the play button and player, use prefabricated C# code. I was wondering if anyone with some experience in this could please help me with this? I need to have the game finished by tomorrow, so a quick answer would be really appreciated :) Here's the code for the start button for some reference:
using UnityEngine;
using System.Collections;
public class PlayButton : MonoBehaviour {
private bool _run = false;
private PlayerControl _playerControl;
void Start(){
_playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>();
}
void OnGUI () {
if (_run == false && GUI.Button (new Rect (Screen.width/2-125,Screen.height/2-35,250,70), "Play")) {
_playerControl.status = true;
_run = true;
}else if (_run == true && GUI.Button (new Rect (10,10,100,50), "Stop")) {
_playerControl.status = false;
_run = false;
}
}
}
Thanks
Harry
I'm almost finished my new game, and the only thing left to implement is the LAN multiplayer.
Translation : "I'm nowhere near finished with my first multiplayer game."
I think that's just a bit harsh. What I mean is that I've finished absolutely everything for one player, I just need a way to make the game multiplayer-capable
So could the next comment please have something to contribute to this conversation? Because I really need some help with this! :)
Not trying to be harsh; I'm just saying that even starting with a completed single-player game, going from that to a multiplayer game is not going to be as easy as you think, and you're in trouble if you need it done by tomorrow. I don't know what your game is, I was guessing it's for a class project and it's something basic like a clone of Atari Combat or Asteroids. If your game is something trivially small and simple like that; then adding multiplayer and getting it working right might take more time than everything else you've done on it. If your game is large and complex, OTOH, and it was not originally scripted with multiplayer in $$anonymous$$d, adding multiplayer could send you back to the drawing board- so either way, you're probably not more than halfway finished.
While I agree with the basic point that multiplayer games are more difficult than a single player game, for the most point, it really is just your opinion and it doesnt help the OP or answer the question. Even if you are 100% correct, which there is no way to prove, as it is just relative observations, it would be nice to at least answer the OPs question on unity resources to get him started, while at the same time giving him your "advice" on whatever you like. Thats how a community should give a "complete" answer while still encouraging.
Answer by tharealjohn · Jun 28, 2013 at 05:53 PM
Have you consider reviewing this area of the documentation?
http://docs.unity3d.com/Documentation/Components/NetworkReferenceGuide.html
It has a great walkthrough of all the concepts of basic client/server relationships in Unity. Unity also provides some nice classes (The Network class) in C# to get a basic LAN system going, where one of the game instances is considered the "server" and the others connect to it. You might have to reorganize some code, because implementing these things can change some of the decisions you make in places.
M2H also has a great reference on this, and some example projects. They used to be on the asset store, but Im not sure if they still are. You can google M2H Networking Tutorial to find them.