How To: Assign Quests At Start

Announcements, support questions, and discussion for Quest Machine.
Post Reply
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

How To: Assign Quests At Start

Post by Tony Li »

This post describes one way to assign a random set of quests to the player at start:

1. Add a QuestGiver component to a GameObject, and assign quests to it.

2. Add a script with a Start() method similar to this:

Code: Select all

void Start()
{
    var questGiver = GetComponent<QuestGiver>();
    for (int i = questGiver.questList.Count - 1; i >= 0; i--) // Loop down in case quests are deleted from list.
    {
        // Flip a coin:
        if (UnityEngine.Random.value < 0.5f)
        {
            var quest = questGiver.questList[i];
            questGiver.GiveQuestToQuester(quest, "Player"); // Give quest to QuestJournal whose ID is "Player".
        }
    }
}
Post Reply