Greetings and Salutations!
I am hard at work on a mobile game project for IOS and have come to a crucial portion of development. The procedurally generated levels. My code is functional at the moment but it seems no matter what I try, I cannot get the Level layouts to vary from stage to stage. Ideally I would seed the RNG with the build index number(or another variable that varies stage to stage but is unique to each stage.) I want each stage's layout to appear random upon first encounter, and be the same each time the stage is entered. Below is the code I am using. I am new to RNGs and am in my first year of programming, so definitely a novice. I have read up a bit about seeding, cryptographic RNG and various other techniques but everything I find online is outdated information that no longer works or at least I cannot get it to work in the current version of unity. Oh and as the title says I am using C#. Thank you for your help!
public GameObject asteroid10hp;
public GameObject asteroid20hp;
public GameObject asteroid30hp;
public int chance10hp;
public int chance20hp;
public int chance30hp;
private GameObject chosenGameObject;
void Start()
{
n = UnityEngine.Random.Range(1, 100);
}
void SpawnUntilFull()
{
Transform freePosition = NextFreePosition();
if (freePosition)
{
MoveRandomly();
RandomAngleGen();
if (n <= chance30hp) { chosenGameObject = asteroid30hp; }
else if (n <= chance20hp) { chosenGameObject = asteroid20hp; }
else if (n <= chance10hp) { chosenGameObject = asteroid10hp; }
if (n <= spawnChance)
{
LevelManager.breakableCount += 1;
GameObject destructible = Instantiate(chosenGameObject, (freePosition.position + moved), Quaternion.Euler(0, 0, angle)) as GameObject;
destructible.transform.parent = freePosition;
}
if (NextFreePosition())
{
Invoke("SpawnUntilFull", spawnDelay);
}
}
}
Transform NextFreePosition()
{
foreach (Transform childPositionGameObject in transform)
{
if ((childPositionGameObject.childCount == 0) & (!childPositionGameObject.CompareTag("Attempted")))
{
childPositionGameObject.tag = "Attempted";
return childPositionGameObject;
}
}
return null;
}