예제 #1
0
	void Start ()
	{
		System.Random rand = new System.Random();
		NameInputField.GetComponent<InputField>().text = "Player_" + rand.Next(9999);
		Instance = this;

		MainMenu.SetActive ( true );

//		for ( int i = 0; i < this.MainMenu.transform.childCount; i++ )
//			this.MainMenu.transform.GetChild ( i ).gameObject.SetActive ( true );

		ConnectMenu.SetActive ( false );
		
		DontDestroyOnLoad ( gameObject );
	}
예제 #2
0
	public void ACCESS_HOST_MENU_BUTTON ()
	{
		
		this.MainMenu.SetActive ( false );

		try
		{

			GameObject serverGameObject = Instantiate ( this.ServerPrefab ) as GameObject;

			if ( serverGameObject != null )
			{

				Server s = serverGameObject.GetComponent <Server> ();

				s.Init ();

				GameObject clientGameObject = Instantiate ( ClientPrefab );
				
				clientGameObject.name = "Host";

				if ( clientGameObject != null )
				{
					Client c = clientGameObject.GetComponent <Client> ();

					c.IsHost = true;
					
					c.ClientName = NameInputField.GetComponent <InputField> ().text;

					if ( c.ClientName == null || c.ClientName == "" || c.ClientName == "Name" )
					{
						c.ClientName = "Host";
					}
					
					c.ConnectToServer ( "localhost", 6321 ); // we're the server, connect to ourself
					// don't hardcode the port.

				}

			}

		} catch ( Exception e )
		{
			Debug.Log ( e.Message );
		}
		
	}
예제 #3
0
	public void CONNECT_TO_SERVER ()
	{
		 
		string hostAddress = this.HostAddressInputField.GetComponent <InputField> ().text;

		if ( hostAddress == null || hostAddress == "" )
			hostAddress = "localhost";

		try
		{

			GameObject clientGameObject = Instantiate ( ClientPrefab );

			clientGameObject.name = "Client";

			if ( clientGameObject != null )
			{
				Client c = clientGameObject.GetComponent <Client> ();
				
				c.IsHost = false;

				c.ClientName = NameInputField.GetComponent <InputField> ().text;

				if ( c.ClientName == null || c.ClientName == "" || c.ClientName == "Name" )
				{
					c.ClientName = "Client";
				}
				
				c.ConnectToServer ( hostAddress, 6321 ); // don't hardcode the port.
				
				this.ConnectMenu.SetActive ( false );
				
			}
		} catch ( Exception e )
		{
			Debug.Log ( e.Message );
		}
		
	}