私のシーンでプレハブをインスタンス化しようとしていますプレハブをインスタンス化するので、私はプレハブをインスタンス化するため、関数一部のデータはTCPプロトコルを介して送信されます。1つの関数でプレハブをインスタンス化する
今、私はちょうどプレハブキューブでをテストしていますが、それは働いていない:
private void addAircraft(Plane plane)
{
listPlane.Add(plane);
//THIS 2 LINES ARE THE PROBLEM
GameObject cube = Instantiate(Resources.Load("Cube", typeof(GameObject))) as GameObject;
cube.transform.position = new Vector3((float)plane.X, 0, (float)plane.Y);
//
planeId_Object_Dictionnary.Add(plane.Flight, cube);
Debug.Log("Plane " + plane.Flight + " is added");
}
をそれは私にエラー戻る:場合でも
Load 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.
を、多くの人がこの問題に遭遇しました。私は関数で私のプレハブをインスタンス化できる解決策を見つけることができません。
飛行機をいつでも追加する必要があるかどうかを確認するための専用のブールチェッカーを用意することができます。 TCP応答マークがtrueの場合は、Update()関数からaddAircraft()を呼び出し、再度falseに設定します。 –
もしあなたがとにかく待っているのであれば、1フレーム遅延は問題ではないと思います。 –