Unity 中的 Update為迴圈,

所以常常很難「停下來」,那如何停下來呢?

 

我們可以運用Time.timescale = 0; 的方式,

就可以讓迴圈暫停囉!

frutwo 發表在 痞客邦 留言(2) 人氣()

利用C# 來取得網頁資料,形成一個文字版瀏覽器~

架設要取得臉書的網頁資料可以這樣寫!

 

using System;
using System.Net;
using System.IO;

namespace Practice
{

     class MainClass
     {

            public static void Main (string[] args)
           {

                    HttpWebRequest httpRequest = null;
                    HttpWebResponse httpResponse;

                    string result = "";
                    String txtURL= "http://wwww.facebook.com";
                    char[] cbuffer = new char[256];
                    int byteRead = 0;
                    try{

                               Uri httpURL = new Uri(txtURL);
                               httpRequest = (HttpWebRequest) WebRequest.Create(httpURL);
                               httpResponse = (HttpWebResponse) httpRequest.GetResponse();
                               System.IO.Stream respStream = httpResponse.GetResponseStream();
                               System.IO.StreamReader respStreamReader =

                                  new StreamReader(respStream);
                               byteRead = respStreamReader.Read(cbuffer, 0, 256);
                               while(byteRead != 0){
                                       string response = new string(cbuffer, 0, byteRead);
                                       result = result+ response;
                                       byteRead = respStreamReader.Read(cbuffer, 0, 256);
                                       Console.WriteLine(response);
                                }

 

                    }
                    catch(Exception ){

                    }


            }


      }


}

frutwo 發表在 痞客邦 留言(0) 人氣()

如果需要在一段時間內撥放音樂,做出類似鬧鐘的功能該如何實現呢?

可以參考下面的程式碼

 

using UnityEngine;
using System.Collections;
using System;//時間相關


public class Time : MonoBehaviour {

 

//音乐文件
public AudioSource music;

 


void OnGUI() {

     DateTime Now = DateTime.Now;
     string year = Now.Year.ToString();

     string week = Now.Date.Month.ToString();

     string day = Now.Date.Day.ToString();
     string hour = Now.Hour.ToString ();
     string minute = Now.Minute.ToString ();
     string second = Now.Second.ToString ();
     print (minute+":"+second);//顯示分與秒單位
     music.Pause();//執行一開始設定音樂暫停
     if (minute == "26")
    {
         if (!music.isPlaying){
         music.Play ();//本機時間26分時音樂撥放
         }
    }
     if (minute == "27")
    {
         if (music.isPlaying){
         music.Pause ();//本機時間27分時音樂暫停
         }
    }

 

void Update () {

      OnGUI ();


}

frutwo 發表在 痞客邦 留言(0) 人氣()

          使用Unity C# 如何取得本機時間呢?

首先在上面多加

using System;

 

再來,

在start裡呼叫DateTime.Now,print函數出來就可以獲得本機時間囉!

void start(){

  

        DateTime Now = DateTime.Now;

        string year = Now.Year.ToString(); 

        string week = Now.Date.Month.ToString();

        string day = Now.Date.Day.ToString();

        print (Now);

        //print(year);只顯示本機時間的年單位

       //print(week);只顯示本機時間的周單位

       //print(day);只顯示本機時間的天單位

     }

 

frutwo 發表在 痞客邦 留言(0) 人氣()