I have 2 scenes, a "town" where you get the quest and a "forest" where you'll complete the quest.
I have it set up so that the quests are persistent between scenes.
What I want to do is that when you go to the "Forest" scene, if you have the FindCoins quest active, it sets to activa a game object with the coins as childs.
Right now, I have a cube in the scene that does that when the player collides with it.
But I'd like it to check if the quest is active when loading the scene.
Quest Control on Scene Load
Re: Quest Control on Scene Load
Hi,
Make sure you're changing scenes using the save system. See: How To: Change Scenes With Save System
Then you can add a script with a Start() method that checks the quest state. Example:
Then add this to a GameObject (e.g., empty GameObject) in the Forest scene, assign the quest, and configure the On Start () event.
Make sure you're changing scenes using the save system. See: How To: Change Scenes With Save System
Then you can add a script with a Start() method that checks the quest state. Example:
Code: Select all
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using PixelCrushers;
using PixelCrushers.QuestMachine;
public class QuestEventOnStart : MonoBehaviour
{
public Quest quest;
public UnityEvent onQuestActive;
IEnumerator Start()
{
for (int i = 0; i < SaveSystem.framesToWaitBeforeApplyData; i++) { yield return null; }
yield return new WaitForEndOfFrame();
if (QuestMachine.GetQuestState(quest.id) == QuestState.Active)
{
onQuestActive.Invoke();
}
}
}