Self Resolve
Quest list from prefabs
I have a prefab that represents my quest panel. And I want to populate the content panel with specified amount of quest prefabs. Therefore I have following code, which wont work no matter how I modify it.
 var quests: GameObject;
 var prefab: GameObject;
 var q: GameObject;
 
 function Start () {
     quests = GameObject.Find("/Canvas/QuestWrapper/SW_quests/Viewport/Content");
     q = new GameObject("GameObject");
     q.transform.parent = quests.transform;
     CreateFromPrefab();
 }
 
 function Update () {
 }
 
  function CreateFromPrefab(){
      q = Instantiate(prefab);
  }
 
               This code creates an empty game object but not the prefab. Therefore I moved CreateFromPrefab() method call into an Update() and wrapped it with if condition, so that it would do it once, like this:
 var quests_created = false;
 function Update () {
     if(!quests_created){
         CreateFromPrefab();
         quests_created = true;
     }
 }
 
 
               However It doesn't change anything. empty gameObject is still there, but no prefab. And If I remove if condition like this:
 function Update () {
     CreateFromPrefab();
 }
 
               It keeps constantly spawning quest prefabs into that empty object I gues. So how do I create an object from prefab once or liminted number of times. I can't figure this out for some time already and it drives me nuts. I will realy apreciate any clues. Once I fix this problem. I will need to change the text for each individual prefab. Is that even posible with prefabs or I am waisting my time right now and I will need to find another solution to make quest list?
Answer by Divole · Oct 14, 2015 at 10:04 AM
Ohhhh Ok, never mind it. I haven't noticed that is was actualy spawning once, but in wrong place - at the top of mu hierarchy. So I fixed it like this:
 var quests: GameObject;
 var prefab: GameObject;
 var q: GameObject;
 
 function Start () {
     quests = GameObject.Find("/Canvas/QuestWrapper/SW_quests/Viewport/Content");    
 }
 var quests_created = false;
 function Update () {
     if(!quests_created){
         CreateFromPrefab();
         quests_created = true;
     }
 }
 
  function CreateFromPrefab(){
      q = Instantiate(prefab);
      q.transform.parent = quests.transform;
  }