怎样才能做到unity获取电脑MAC地址呢?现在我们就来看一下。

NetworkInfo.cs
using UnityEngine;
using System.Collections;
using System.Net.NetworkInformation;
using System;
public class NetworkInfo {
    public static void DisplayTypeAndAddress()
    {
        //IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
        Debug.Log(nics.Length + " nics");
        //Debug.Log("Interface information for "+computerProperties.HostName+"."+computerProperties.DomainName);
        foreach (NetworkInterface adapter in nics)
        {
            IPInterfaceProperties properties = adapter.GetIPProperties();
            Debug.Log(adapter.Description);
            Debug.Log(String.Empty.PadLeft(adapter.Description.Length, '='));
            Debug.Log("  Interface type .......................... : " + adapter.NetworkInterfaceType);
            Debug.Log("  Physical Address ........................ : " + adapter.GetPhysicalAddress().ToString());
            Debug.Log("  Is receive only.......................... : " + adapter.IsReceiveOnly);
            Debug.Log("  Multicast................................ : " + adapter.SupportsMulticast);
        }
    }
 void OnGUI(){
   //GUI.Label (Rect (10, 10, 100, 20),nics.adapter.GetPhysicalAddress().ToString());
 }
}


然后再另外的地方调用这个类。
NetworkInfo.DisplayTypeAndAddress(); //调用NetworkInfo.cs里面的DisplayTypeAndAddress()函数。