unity3d與web互動的方法

來源:互聯網
上載者:User

介紹一下UNITY3D與WEB互動的方法,包含傳入和傳出

通過web,url傳入數值的方法:

代碼:

var version : int = 1;

function CheckVersion ()
{
var update_url = "http://mysite.com/myGame/version.txt";
update_post = WWW(update_url);
yield update_post; //等待資料傳遞
if(update_post.error)
{
print("URL輸入錯誤: " + update_post.error);
}
else
{
var latestVersion : int;
//取得傳入的值
latestVersion = int.Parse(update_post.data);
if (latestVersion > version)
{
//你的代碼寫在下面
}
}
}

unity3d輸出資料的方式如下,採用Application.ExternalCall,該方法只適合在web3d環境下使用。
該方法支援基本類型的傳遞和數組傳遞,任何類型都會轉換成字串類型使用。
例子代碼://不待參數的調用函數 MyFunction1
Application.ExternalCall ("MyFunction1");

//調用函數MyFunction2,傳遞一個字串
Application.ExternalCall ("MyFunction2", "Hello from Unity!");

//調用函數MyFunction3,傳遞混合參數
Application.ExternalCall ("MyFunction3", "one", 2, 3.0);

在web中使用的函數,接受參數的能力。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.