I have a problem.
I have a class Label which is drawing the text. Label is depending of some resources (image characters and stuff).
I also have a main object in my scene called Resources. When my game is loading. i’m loading resources.
public class Resources : MonoBehaviour {
public Dictionary<char, Sprite> chars; //chars for font
void Awake(){
loadFont("font33chars", chars); //for font 33
}
}
Then, i’m using these loaded characters to draw the text.
public class Label : MonoBehaviour {
void Start(){
chars = singleton.i.resources.chars;
drawText("ba bla "); //depending on chars
}
Lets say I have many labels in my game and this works totally fine.
Later I wanted to create this Label in runtime using prefab (which is in the resources folder).
it’s also pretty easy
var pfLabel = (GameObject)Resources.Load("Label", typeof(GameObject));
var label = (GameObject)Instantiate(pfLabel, transform.position, Quaternion.identity);
label.GetComponent<whatever>().drawText("bla bla runtime")
and here there’s a problem. because when i’m calling method drawText (which is depending on method start) - i’m realizing that start didnt run yet. so, my characters are not loaded and i cant draw a text.
i read this article
http://forum.unity3d.com/threads/24986-prefab-instantiation-start-problem
but in my case i can’t do it like this.
I can’t use Awake method in Label to load resources.
because i’m using Label on the scene and as a prefab in the same time (maybe its wrong).
and when it’s loading on the scene then when Label.Awake is called - my resources are not ready.
this is really confusing. i hope you understood. Tell me what to do in this situation.