Hi.
Excuse my english. I don’t find answers in french forum.
I create a box with a networkview and a control script.
private var vitesse : float = 0.05;
function Start () {
}
function Update () {
if(networkView.isMine){
Deplacement();
}else{
this.enabled = false;
}
}
function Deplacement(){
if ( Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.UpArrow) )
transform.Translate(Vector3.forward * vitesse);
else if ( Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow) )
transform.Translate(Vector3.back * vitesse);
if ( Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.LeftArrow) )
transform.Rotate(Vector3.up *-2);
else if ( Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) )
transform.Rotate(Vector3.up * 2);
if ( Input.GetKeyDown(KeyCode.Space) ) //le saut
rigidbody.AddForce(Vector3.up * 350);
}
And a networkManager which diplay a menu, launch a server and instantiates box.
var playerPrefab : GameObject;
var spawnObject : Transform;
var gameName : String;
var gameType : String;
var gameComment : String;
gameName = "areabattlealacon";
gameType = "jeudemerde";
gameComment = "binestuntest";
private var hostData : HostData[];
private var btnX : float;
private var btnY : float;
private var btnW : float;
private var btnH : float;
/*MasterServer.ipAddress = "127.0.0.1";
MasterServer.port = 23466;
Network.natFacilitatorIP = "127.0.0.1";
Network.natFacilitatorPort = 50005;*/
function Start(){
btnX = Screen.width*0.05;
btnY = Screen.height*0.05;
btnW = Screen.width*0.1;
btnH = Screen.width*0.1;
}
function OnGUI(){
if(!Network.isClient !Network.isServer){
if(GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start Server")){
Debug.Log("Starting server");
startServer();
}
if(GUI.Button(Rect(btnX, btnY*1.2+btnH, btnW, btnH), "Refresh Hosts")){
Debug.Log("Refreshing");
refreshHostList();
}
if(hostData){
for(var i:int= 0;i<hostData.length; i++){
if(GUI.Button(Rect(btnX*1.5+btnW,btnY*1.2+(btnH*i),btnW*3,btnH*0.5),hostData[i].gameName)){
Network.Connect(hostData[i]);
}
}
}
}
}
function startServer(){
Network.InitializeServer(32,25000,!Network.HavePublicAddress);
MasterServer.RegisterHost(gameName,gameType,gameComment);
}
function spawnPlayer(){
Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
}
function OnServerInitialized(){
Debug.Log("Server Initialized");
spawnPlayer();
}
function OnConnectedToServer(){
spawnPlayer();
}
function OnMasterServerEvent(mse:MasterServerEvent){
if(mse == MasterServerEvent.RegistrationSucceeded){
Debug.Log("Registred server in master server");
}
}
function refreshHostList(){
MasterServer.RequestHostList(gameName);
yield WaitForSeconds(2);
hostData = MasterServer.PollHostList();
Debug.Log(MasterServer.PollHostList().Length);
}
My problem is :
If I launch my server and then my client. The box created by the client is controled by the server.
The server take the control of the new box. The old box can’t be controled.
Help me please.
Thx.