Unity绑定电脑MAC地址
新建一个脚本MAC_Test,挂载到任意物体上
using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using UnityEngine;
public class MAC_Test : MonoBehaviour
{
private void Start()
{
Debug.Log("mac:" + GetMacAddress());
}
private static string GetMacAddress()
{
string physicalAddress = "";
NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adaper in nice)
{
Debug.Log(adaper.Description);
if (adaper.Description == "en0")
{
physicalAddress = adaper.GetPhysicalAddress().ToString();
break;
}
else
{
physicalAddress = adaper.GetPhysicalAddress().ToString();
if (physicalAddress != "")
{
break;
};
}
}
return physicalAddress;
}
}