Network.HavePublicAddress 有公网地址?

static function HavePublicAddress () : bool

Description描述

Check if this machine has a public IP address.

检测这台机器是否有一个公网IP地址。

It checks all the network interfaces for IPv4 public addresses and returns true if one address is found.

检查所有网络接口来获取Ipv4公网地址,如发现返回true。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnGUI() {
		if (GUILayout.Button("Start Server")) {
			bool useNat = !Network.HavePublicAddress();
			Network.InitializeServer(32, 25002, useNat);
			MasterServer.RegisterHost("MyUniqueGameType", "JohnDoes game", "l33t game for all");
		}
	}
}
function OnGUI() {
	if (GUILayout.Button ("Start Server")) {
		// Use NAT punchthrough if no public IP present
		//如果没有公网IP,使用NAT穿透
		var useNat = !Network.HavePublicAddress();
		Network.InitializeServer(32, 25002, useNat);
		MasterServer.RegisterHost("MyUniqueGameType",
		"JohnDoes game", "l33t game for all");
	}
}
Page last updated: 2011-4-4