Hi all, I am creating an RPG which has a working quest assign system. However, I am confused with how to add the quests name and description to the UI and end up running into errors. The quests assign correctly and complete under the correct conditions. I have a quest log that appears then the user presses the "Q" key. Any advice on how to tackle this would be greatly appreciated! The quest manager code: Code (CSharp): public class Quest: MonoBehaviour public List<Quest> Quests { get; set; } public List<Goal> Goals { get; set; } = new List<Goal>(); public string QuestName { get; set; } public string Description { get; set; } public int ExperienceReward { get; set; } public bool Completed { get; set; } public void CheckGoals() { Completed = Goals.All(g => g.Completed); if (Completed) GiveReward(); } void GiveReward() { Debug.Log("Player given reward."); } } And the quest giver code: Code (CSharp): public class QuestGiver : NPC { public List<Quest> Quests { get; set; } = new List<Quest>(); public bool AssignedQuest { get; set; } public bool Helped { get; set; } [SerializeField] private GameObject quests; [SerializeField] private string questType; private Quest Quest { get; set; } public override void Interact() { if (!AssignedQuest && !Helped) { base.Interact(); AssignQuest(); } else if (AssignedQuest && !Helped) { CheckQuest(); } else { DialogueSystem.Instance.AddNewDialogue(new string[] { "Appreciate you helping me out, adventurer!" }, name); } } void AssignQuest() { AssignedQuest = true; Quest = (Quest)quests.AddComponent(System.Type.GetType(questType)); //Quest.Quests.Add(Quest); AddToQuestLog(); } void CheckQuest() { if (Quest.Completed) { Helped = true; AssignedQuest = false; DialogueSystem.Instance.AddNewDialogue(new string[] { "Thanks! Here's your reward!", "You're the best" }, name ); } else { DialogueSystem.Instance.AddNewDialogue(new string[] { "Did you get that task done for me?"}, name); } } void AddToQuestLog() { Debug.Log("Quest added to log!"); //questName.text = Quests[0].QuestName; //questDescription.text = Quests[0].Description; } }
I suggest not to coouple log tightly to quest system. Create a LogEntry class and a UI to display list of such entries. After that you may create game events like quest given / quest completed and when such events appears in game add new LogEntry to the log