Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#在执行代码之前,等待co例程完成_C#_Php_Mysql_Unity3d - Fatal编程技术网

c#在执行代码之前,等待co例程完成

c#在执行代码之前,等待co例程完成,c#,php,mysql,unity3d,C#,Php,Mysql,Unity3d,嗨,我正在尝试实现从sql数据库保存/加载到我的游戏中。 我有它所有的工作,除了事实上,我需要点击加载两次,它加载数据 设置数据的代码在我有机会设置它之前完成 public void loadData() { GetComponent<SavingLoading>().Load(GameObject.Find("LoginSystem").GetComponent<LoginSystem>().Username); if (GetComponent<

嗨,我正在尝试实现从sql数据库保存/加载到我的游戏中。 我有它所有的工作,除了事实上,我需要点击加载两次,它加载数据

设置数据的代码在我有机会设置它之前完成

public void loadData()
{
    GetComponent<SavingLoading>().Load(GameObject.Find("LoginSystem").GetComponent<LoginSystem>().Username);

    if (GetComponent<SavingLoading>().LoadedData != "")
    {
        string[] Data = GetComponent<SavingLoading>().LoadedData.Split(',');

        Level = Convert.ToInt32(Data[0]);
        CurrentXp = Convert.ToInt32(Data[1]);
        currentHealth = Convert.ToInt32(Data[2]);
        maxHealth = Convert.ToInt32(Data[3]);

        Vector3 LoadedPos = new Vector3(Convert.ToSingle(Data[4]), Convert.ToSingle(Data[5]), Convert.ToSingle(Data[6]));
        transform.position = LoadedPos;
    }
}
如果存在数据,我如何仅更新数据?不必按两次加载按钮。

根据,您应该将www变量包装在using语句中,以便正确地处理它。然后从中获得回报,如下所示:

using (WWW www = new WWW(url))
{
    yield return www;
    string _return = www.text;
    LoadedData = _return;
}

我不知道你所说的“只有在有数据的情况下才更新数据”是什么意思。您是否有更多代码可以显示,这可能有助于澄清您的意图?

您想等到协同程序完成后再看吗?将该代码放入协同程序中或添加回调函数参数。虽然可能是准确的,但这实际上并不能回答他们的问题。
using (WWW www = new WWW(url))
{
    yield return www;
    string _return = www.text;
    LoadedData = _return;
}