Hello there, am creating network game. I followed one of the tutorial and create a script for network connection, now am having this error.
Error : “Cannot implicitly convert type UnityEngine.HostData[]' to bool’”
here is the code:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour
{
public GameObject Car;
public Transform Spawn_Point;
public string Game_Name = "Car_Game";
private bool Refreshing;
bool Network_Service;
private float Button_x;
private float Button_y;
private float Button_w;
private float Button_h;
private HostData[] Server_Data;
void Start()
{
Button_x = Screen.width * 0.05f;
Button_y = Screen.width * 0.05f;
Button_w = Screen.width * 0.1f;
Button_h = Screen.width * 0.1f;
}
void StartServer()
{
Network_Service = !Network.HavePublicAddress();
Network.InitializeServer(32, 25001, Network_Service);
MasterServer.RegisterHost(Game_Name, "Car_Game", "This is a test");
}
void RefreshHostList()
{
MasterServer.RequestHostList (Game_Name);
Refreshing = true;
}
void Update()
{
if(Refreshing)
{
if(MasterServer.PollHostList().Length > 0)
{
Refreshing = false;
Server_Data = MasterServer.PollHostList ();
}
}
}
void CarSpawn()
{
Network.Instantiate (Car, Spawn_Point.position, Quaternion.identity, 0);
}
void OnServerInitiatlized()
{
Debug.Log ("Server Initialisation");
CarSpawn ();
}
void OnConnectedToServer()
{
CarSpawn ();
}
void OnMasterServerEvent(MasterServerEvent MSE)
{
if(MSE == MasterServerEvent.RegistrationSucceeded)
{
Debug.Log ("Registered Server");
}
}
void OnGUI()
{
if(!Network.isClient && !Network.isServer)
{
if(GUI.Button(new Rect(Button_x, Button_y, Button_w, Button_h),"Start Server"))
{
Debug.Log ("Starting Server");
StartServer();
}
if(GUI.Button(new Rect(Button_x, Button_y * 3 + Button_h, Button_w, Button_h),"Refresh Host"))
{
Debug.Log ("Refreshing");
RefreshHostList();
}
if(Server_Data)
{
for(int i = 0; i < Server_Data.Length; i++)
{
if(GUI.Button(new Rect(Button_x * 1.5f + Button_w, Button_y * 1.2f + (Button_h * i), Button_w * 3, Button_h * 0.5f),Server_Data*.gameName))*
Network.Connect(Server_Data*);
_ }_
_ } _
_ }_
_ }_
_}_
_-Prasanna*_