Why won't my network code run on LAN?

Here’s my network code, I can connect on the same machine but when I try two separate computers it won’t connect.

var ServerIP: String = "";
var ServerPort: String = "30000";

function OnGUI(){
if (Network.peerType == NetworkPeerType.Disconnected){
	if (GUILayout.Button("Connect")){
		Network.Connect(ServerIP, parseInt(ServerPort));
	if (GUILayout.Button("New Server")){
		Network.InitializeServer(32, parseInt(ServerPort), false);	
	 if (GUILayout.Button("Disconnect")){

The ip address is connecting to the same machine, to connect to a different machine you need that machine’s ip address.
If the other computer is on your internet network(e.g. connected to your wifi) then you can connect using it’s local ip. If it is not then you will need to port forward the global ip through your firewall so you can host a server on it.
I would suggest looking up some youtube videos on minecraft server setups as I find they help explain port forwarding.

However, if I were you I would be using unity’s master server functionality. It is much more advanced and in this example you don’t need to worry about knowing the server’s ip directly.

Some useful links:

I hope this helps

Here is my Code,
Still trying to work out how to destroy objects neatly.

using UnityEngine;
using System.Collections;

public class LanNetworkManager : MonoBehaviour {

	public string gameName = "not needed for lan";
	public string hostGameName = "Tutorial Networking";
	public GameObject playerPrefab;
	public Transform spawnObject;
	public int maxPlayers = 6;

	private string ip = "";
	private int playerCount = 0;
	private bool gameStarted = false;

	private int btnX;
	private int btnY;
	private int btnW;
	private int btnH;

	void Start(){
		btnX = 10;
		btnY = 10;
		btnW = 130;
		btnH = 20;

	void startServer(){
		bool useNat = false; //!Network.HavePublicAddress ();
		Network.InitializeServer (maxPlayers, 25017,useNat);

	void OnServerInitialized(){
		Debug.Log ("Server Started");
		spawnPlayer ();

	void OnConnectedToServer(){
		Debug.Log ("Server Joined");
		spawnPlayer ();

	void ConnectToLanServer(string ipA){
		Network.Connect (ipA, 25017);

	void OnPlayerConnected(){
		Debug.Log ("Player Connected");

	void OnPlayerDiconnected(){
		Debug.Log ("Player Diconnected");


	void OnGUI(){
		if (!Network.isClient && !Network.isServer && !gameStarted) {
			if (GUI.Button (new Rect (btnX, btnY, btnW, btnH), "Start Server")) {
				gameStarted = true;
				startServer ();
			ip = GUI.TextField (new Rect (btnX, btnY * 4, btnW, btnH), "");
			if (GUI.Button (new Rect (btnX, btnY * 7, btnW, btnH), "Manual Connect")) {
				gameStarted = true;
				ConnectToLanServer (ip);
		} else {
			if(GUI.Button (new Rect(btnX,btnY*11,btnW,btnH),"Disconnect")){
				gameStarted = false;
		if (Network.isServer) {
			GUI.Label (new Rect(btnX,btnY*15,btnW,btnH),"Players: " + (playerCount + 1) + "/" + maxPlayers);

	void PlayerSpawned(){
		Debug.Log ("Player Spawned");

	void spawnPlayer(){
		Network.Instantiate (playerPrefab, spawnObject.position, Quaternion.identity, 0);
		PlayerSpawned ();