- Home /
Add spawn to script [Multiplayer]
How do I make that Of I host a server I will spawn and can play and if someone joins me they will spawn to? Here's the code and I want to spawn player on server start with help from
var playerPrefab : Transform
var SpawnPoint : Transform
var ipAddress : String = "127.0.0.1";
var port : int = 25000;
var maxConnections : int = 10;
function OnGUI () {
GUILayout.BeginHorizontal ();
ipAddress = GUILayout.TextField (ipAddress);
GUILayout.Label ("IP ADDRESS");
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
var tempPort : String;
tempPort = GUILayout.TextField (port.ToString());
port = parseInt(tempPort);
GUILayout.Label ("PORT");
GUILayout.EndHorizontal();
if(GUILayout.Button ("CONNECT")) {
print("connecting... ");
Network.Connect (ipAddress, port);
}
if(GUILayout.Button ("START SERVER")) {
print("starting server on " + ipAddress + ":" + port);
Network.InitializeServer (maxConnections, port);
}
}
function OnConnectedToServer () {
print("connected");
}
Just bumping this question won't help.
Community expects some efforts from you regarding the solution you are looking for and in your code there is noting related to the task you are trying to accomplish. Your code is just for selecting a server and connecting to it.
If you really want to find out about how to spawn objects and control them in a multiplayer game then there are tons of tutorials on the web and questions on UA for the same.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Network disconnect player 1 Answer
RPC Call Error/Failed 1 Answer
ReplacePlayerForConnection works but... 0 Answers
No appropriate version of 'UnityEngine.Object.Instantiate' 0 Answers