How To: Spawn in Other Scenes

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

How To: Spawn in Other Scenes

Post 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.
Post Reply