So, i have this problem. I have a function that gets quests by id, but when i call the function, only the newest quest added displays text in the game.
An example: I have the function GetQuestByID(int id), and in the database i have 3 quests, they all have an id, 0, 1, 2. But when i call them from start, only the quest with id 2 gets shown in the text component, is it because im only saying getcomponentinchildren.text and not getcomponents in children, so it keeps overwriting itself with the newer quest?
TLDR: How do i make it so the text components and the quests show below eachother? the gui is set up perfectly, where the text is aligned below eachother, it just doesnt want to show the quest description below eachother, and only in the first slot instantiated.
Code:
//QUESTINFO
[System.Serializable]
public class QuestInfo{
public string _name;
public string questDescription;
public int questExpToGive;
public int killAmount;
public int questID;
public QuestInfo(string Name, int QID, string QDesc, int QExp, int QkillAm)
{
_name = Name;
questID = QID;
questDescription = QDesc;
questExpToGive = QExp;
killAmount = QkillAm;
}
public QuestInfo()
{
}
}
//QUEST DATABASE
public class QuestDatabase : MonoBehaviour {
public List<QuestInfo> quests = new List<QuestInfo>();
void Start()
{
quests.Add(new QuestInfo("CrabQuest", 0, "Kill 5 crabs", 300, 5));
quests.Add(new QuestInfo("WolfQuest", 1, "Kill 5 sheeps", 500, 5));
quests.Add(new QuestInfo("WellQuest", 2, "Find the well!", 1000,0));
}
}
//QUESTHANDLER
public class QuestHandler : MonoBehaviour {
public GameObject QuestDescPrefab;
public List<QuestInfo> quests = new List<QuestInfo>();
private QuestDatabase questDB;
public int y = 100;
void Start()
{
questDB = GameObject.FindGameObjectWithTag("QuestDatabase").GetComponent<QuestDatabase>();
for(int i = 0; i < questDB.quests.Count; i++)
{
GameObject txtPrefab = Instantiate(QuestDescPrefab) as GameObject;
quests.Add(new QuestInfo());
txtPrefab.transform.SetParent(this.gameObject.transform);
txtPrefab.GetComponent<RectTransform>().localPosition = new Vector3(0,y,0);
/*txtPrefab.*/
y = y - 40;
}
GetQuestByID(0);
GetQuestByID(1);
GetQuestByID(2);
}
void GetQuestByID(int id)
{
for(int i = 0; i < questDB.quests.Count; i++)
{
if(questDB.quests*.questID == id)*
-
{*
quests = questDB.quests*;*
_ GetComponentInChildren().text = questDB.quests*.questDescription;
break;
}
}
}
}*_