切換
舊版
前往
大廳
主題

(Unity) 假裝當機的程式

浪濤書記 | 2019-04-15 09:58:39 | 巴幣 8 | 人氣 442


忘了在哪看到的趣聞,
把程式掛在遊戲裡的任意地方,
遊戲就可以在執行一段時間後 自動關閉,
沒什麼用途,純粹能讓後頭接手專案的人以為有Bug,
被逼著修復,結果花費大量時間,
找到的卻是這個莫名其妙的程式。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 假裝當機程式 (設定秒數後讓遊戲自己關閉)
/// </summary>
public class Ultimate_Crash_Script : MonoBehaviour {

    /// <summary>
    /// 關閉遊戲的延遲秒數
    /// </summary>
    public float delayTime;


    // Use this for initialization
    void Start () {
        DontDestroyOnLoad(this);
        StartCoroutine(Crash_Simulate(delayTime));
    }

    /// <summary>
    /// 模擬當機 (指定秒數後關閉遊戲)
    /// </summary>
    /// <param name="tTime"> 指定的秒數 </param>
    IEnumerator Crash_Simulate(float tTime) {
        yield return new WaitForSeconds(tTime);
        #if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
        #else
        Application.Quit();
        #endif
    }

}

※順便試試看下面這篇文提供的貼程式碼方式,挺好用的。
https://forum.gamer.com.tw/C.php?bsn=60292&snA=4879
送禮物贊助創作者 !
0
留言

創作回應

更多創作