why unity shows this message?
get_isActiveAndEnabled can only be called from the main thread.Constructors and field initializers will be executed from the loading thread when loading a scene.Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.UI.Text:set_text(String)loader:DownloadFileCompleted(Object, AsyncCompletedEventArgs) (at Assets/loader.cs:29)System.Net.WebClient:m__E(Object)
Please help?
using UnityEngine;
using System;
using UnityEngine.UI;
using System.Net;
public class loader : MonoBehaviour {
public Text mesaj;
public string filename,filename2;
public void dosyaoku()
{
WebClient client = new WebClient();
client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadFileCompleted);
filename2 = Application.dataPath + "/" + "FiyatListesi.csv";
client.DownloadFileAsync(new Uri("https://docs.google.com/spreadsheets/d/mysheetid/export?format=csv&id="mysheetid&gid=gidnumber"), filename2);
}
void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error == null)
{
AllDone();
}
else
{
mesaj.text = e.Error.Message;
}
}
private void AllDone()
{
mesaj.text = "file downloaded";
}
}
↧