Hello again,
I'm looking for a method to implement a sequence that loads a scene at random from a list of possible scenes to allow for random events to trigger at certain transitions between conversations. Is this currently doable within DS or am I looking at some custom scripting?
I've had a look at the loadlevel sequencer script and I believe it should be possible to add some code that accepts a list of scene names and loads one at random, resulting in a sequence command similar to;
LoadRandomLevel(Level1, Level2, Level3)
I've not had a lot of time today to look into creating said script but I plan to attempt this tonight but if it is possible already or if anyone has any suggestions with regards to fashioning the script, please let me know
Cheers
LoadLevel sequencer for reference;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class SequencerCommandLoadLevel : SequencerCommand {
public void Start() {
string levelName = GetParameter(0);
if (!string.IsNullOrEmpty(levelName)) {
PersistentDataManager.Record(); // Let current persistent objects save themselves.
Application.LoadLevel(levelName);
}
Stop();
}
}
Load random scene/level
Re: Load random scene/level
Hi,
Try this:
SequencerCommandLoadRandomLevel.cs
It uses the SequencerCommand class's Parameters property.
It also uses the scene's Level Manager if present; otherwise it uses Tools.LoadLevel along with updating the scenes' persistent data.
Try this:
SequencerCommandLoadRandomLevel.cs
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class SequencerCommandLoadRandomLevel : SequencerCommand
{
public void Start()
{
string levelName = Parameters[Random.Range(0, Parameters.Length)];
var levelManager = FindObjectOfType<LevelManager>();
if (levelManager != null)
{
levelManager.LoadLevel(levelName);
}
else
{
PersistentDataManager.Record();
PersistentDataManager.LevelWillBeUnloaded();
Tools.LoadLevel(levelName);
PersistentDataManager.Apply();
}
Stop();
}
}
It also uses the scene's Level Manager if present; otherwise it uses Tools.LoadLevel along with updating the scenes' persistent data.
Re: Load random scene/level
Fantastic, that works exactly as I was hoping for!
I had a couple of hours set aside to try and get it working but I can cross that off now and move on to something else, thanks a lot Tony.
I had a couple of hours set aside to try and get it working but I can cross that off now and move on to something else, thanks a lot Tony.
Re: Load random scene/level
Happy to help!