Hi! Look at first lines of my code. I have a cube. If I click on cube the server Start and If I click on it again the server must Stop.
var debugo = false;
var debugo1 = false;
var primo : boolean;
function OnMouseDown(){
primo=!primo;
if(primo){
LaunchServer();
}
if(!primo){
Disconnetti();
}
}
function LaunchServer () {
var useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 25000, useNat);
}
/////////////////////////////////////////
function Disconnetti(){
Network.Disconnect();
MasterServer.UnregisterHost();
}
///////////////////////////////////////////
function OnServerInitialized() {
Debug.Log("Server initialized and ready");
debugo=true;
}
private var playerCount: int = 0;
function OnPlayerConnected(player: NetworkPlayer) {
debugo1=true;
Debug.Log("Player " + playerCount++ +
" connected from " + player.ipAddress +
":" + player.port);
// Populate a data structure with player information ...
}
function OnGUI () {
if (debugo==true){
GUI.Label (Rect (10, 10, 250, 20), "Server lanciato correttamente");
}
if (debugo1==true){
GUI.Label (Rect (10, 40, 250, 20), "Giocatore Collegato");
}
}
The problem is that when I click for the first time on the cube I’ll not have only one debug message (Server initialized and ready) but 3 or 4. Same when I re-click on the cube I’ll have many Degug messages.
I think the problem is the following but I’m not sure
function OnMouseDown(){
primo=!primo;
Thanks!