Can you please tell me how to call a scene randomly without repeating the scene that has already called… thank you in advance guys.
Keep a list of where you’ve been.
Choose a random scene.
While ( randomScene is in whereHaveBeen )
-choose new random scene
it will not repeat the present scene… but it will be possible that the previous scene will be called… i will apply this to a questionnaires, each scene has one question so that’s why im trying to invoke the calling of repeating scene…
I hate to be -that- guy, but take time with your posts. Even adding 2 minutes worth of brain power to each post and you’d get a lot clearer answers. No one wants to help you if it feels like they’re doing 100% of the work for you. If your english isn’t good, than add at the bottom your primary language so someone who knows it as well can help you more clearly.
Make an array made of strings (the names of the available levels).
You get a random number, by using Random.Range. Whenever you load a random level, use RemoveAt function, so it is removed from the array.
using UnityEngine;
using System.Collections.Generic;
public static class SceneManager
{
private const int kNumScenes = 5;
private static List<int> s_SceneList = null;
public static bool NextScene ()
{
if (s_SceneList == null)
{
s_SceneList = new List<int> ();
for (int i = 1; i <= kNumScenes; i++)
{
s_SceneList.Add (i);
}
for (int i = 0; i < s_SceneList.Count; i++)
{
int index = Random.Range (0, s_SceneList.Count);
s_SceneList.Add (s_SceneList [index]);
s_SceneList.RemoveAt (index);
}
}
if (s_SceneList.Count < 1)
{
return false;
}
int scene = s_SceneList [0];
s_SceneList.RemoveAt (0);
Application.LoadLevel (scene);
return true;
}
}
thank you mr akilae and angryant.
@windexglow- i dont have time to think about the code so that’s why i need the help of others urgently and sir why don’t you try to monitor your english and ignore mine… You don’t have to be sarcastic just to note my English.
mmm…I jumped upon this and I need it…where to put that code exactly?
im using the code and its not working. can you explain further what to do ?
I generally tend to use the deck of cards method. Keep a list of your scenes (cards), then as you pull a card, remove it from that stack.
How you pull the cards is up to you. Randomly, off the top, off the bottom…
yes very much