Unity displays time, battery and network

As we all know, with the development of these years, mobile games have become more and more sticky, and the time spent in the game interface has become longer and longer. I myself often need to switch to the main page in the game to get information such as time and power. This article mainly realizes the display of time, power and network information in Unity.


  • time:
System.DateTime.Now.ToLongTimeString()
  • Power:
// 5.3版本还没支持,我现在用的5.6版本已经支持了
// PC会返回 -1
SystemInfo.batteryLevel.ToString()
SystemInfo.batteryLevel.ToString()
  • The internet:
string network = string.Empty;
if (Application.internetReachability == NetworkReachability.NotReachable)
    network = "当前网络:不可用";
else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
    network = "当前网络:3G/4G";
else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
    network = "当前网络 : WIFI";

If there are any mistakes, please point them out.

email:dxmdxm1992#gmail.com

blog: http://blog.csdn.net/david_dai_1108

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325449268&siteId=291194637