Page 1 of 1

How To: Spawn in Other Scenes

Posted: Sun Jul 12, 2020 4:09 pm
by Tony Li
If you have a quest that spans scenes, you might want to spawn something in another scene when the quest is active and the player enters that scene. The easiest solution is a little script that checks the state of a quest and potentially spawns something. Example:

SpawnOnStart.cs

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;

public class SpawnOnStart : MonoBehaviour
{
    public StringField questID;
    public QuestState requiredState = QuestState.Active;
    public GameObject prefabToSpawn;
    
    void Start()
    {
        if (QuestMachine.GetQueststate(questID) == requiredState)
        {
            Instantiate(prefabToSpawn);
        }
    }
}
Add this script to the scene, and set questID, requiredState, and prefabToSpawn.