- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
bob brazil · Oct 03, 2013 at 08:18 PM ·
networkcontrollerserver
character controller problem on network
Hi i have a simple network system ,but when I instantiate a player ,He controls the cliente .,and client controls the server ,what i do ?
//Network script in C#
using System.Collections; public class ServerController : MonoBehaviour {using UnityEngine;
public string ipToConnect; public int portToConnect; public int numberPlayers;
// Use this for initialization void Start () { ipToConnect = Network.player.ipAddress; }
// Update is called once per frame void Update () {
}
void StartServer(){ if(Network.peerType == NetworkPeerType.Disconnected){ Debug.Log(Network.InitializeServer(numberPlayers, portToConnect, false)); } }
void ConnectToServer(){ if(Network.peerType == NetworkPeerType.Disconnected){ Debug.Log(Network.Connect(ipToConnect, portToConnect)); } }
void OnGUI(){ if(Network.peerType == NetworkPeerType.Disconnected){ if(GUI.Button(new Rect(Screen.width/2-100, 10, 200, 30), "Inicializar Servidor")){ StartServer(); } ipToConnect = GUI.TextField(new Rect(Screen.width/2-100, 40, 200, 30), ipToConnect); if(GUI.Button(new Rect(Screen.width/2-100, 70, 200, 30), "Conectar ao Servidor")){ ConnectToServer(); } } }
//Player script in Java #pragma strict var velocidadeFrente : float; var velocidadeCima : float; var velocidadeLado : float;
function Start () { if (!networkView.isMine) { enabled =false; } }
function Update () {
if (networkView.isMine)
velocidadeCima = 30*Time.deltaTime; velocidadeFrente = 50*Time.deltaTime; velocidadeLado = 40*Time.deltaTime;
if(Input.GetKey("w")) { transform.Translate(0,0,velocidadeFrente); }
if(Input.GetKey("s")) { transform.Translate(0,0,-velocidadeFrente); }
if(Input.GetKey("a")) { transform.Translate(-velocidadeLado,0,0); } if(Input.GetKey("d")) { transform.Translate(velocidadeLado,0,0); } }
Comment
does this help you? http://answers.unity3d.com/questions/206617/network-fps-help-asap.html
by the way are you using a server in particular? i wanted to start making multiplayer game but with no good documentation i just left my project behind
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
other players and the server does not receive networkView.RPC 1 Answer
Orbit Script V2 Walking Problem 0 Answers