Unity 控制重启与关机(Linux 系统)

windows系统没有测试

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//超过3次重启要关机
public class Test : MonoBehaviour
{
    
    int restartTime;
    void Start()
    {   
        restartTime= PlayerPrefs.GetInt("Restart",restartTime);
         Debug.Log(restartTime);
         if(restartTime>=1)
         {
              PlayerPrefs.SetInt("Restart",0);
                  System.Diagnostics.Process.Start("shutdown", @"-h -t 00");//立即关机
         }
         else
         {
             restartTime+=1;
             PlayerPrefs.SetInt("Restart",restartTime);
             System.Diagnostics.Process.Start("shutdown", @"-r -t 00");//立即重启 
         }        
    }
   
   
}

 

你可能感兴趣的:(Unity 控制重启与关机(Linux 系统))