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中使用的函数,接受参数的能力。

原文地址:https://www.cnblogs.com/yanghaihao/p/2805036.html