I’m trying to save a random seed to a PlayerPref so the game loads the same world each time, after its been created once first. I know this is wrong, but this is what I have so far.
public int GameWidth;
public int GameHeight;
public int SeedNumber;
public int MapCreated = 0;
// Use this for initialization
void Start () {
if(MapCreated != 1)
{
for(int z = 0; z < GameHeight; z++)
{
for(int x = 0 ; x < GameWidth; x++)
{
float rnd = Random.value;
if(rnd <0.25f)
{
Instantiate(TileOne, new Vector3(x,0,z), Quaternion.identity);
}
else if(rnd <0.5f)
{
Instantiate(TileTwo, new Vector3(x,0,z), Quaternion.identity);
}
else
{
Instantiate(TileThree, new Vector3(x,0,z), Quaternion.identity);
}
}
}
PlayerPrefs.GetInt("MapCreated", 1);
SeedNumber = Random.Range(1,1000);
}
if(MapCreated == 1)
{
PlayerPrefs.GetInt("Seed", SeedNumber);
Random.seed = SeedNumber;
}
}
I’m trying to do it like this
Create world.
Get worlds seed.
Save the worlds seed.
Use the saved seed from now on when loading the world.
I think most of my problem comes from the fact that I’m not sure how to use PlayerPrefs correctly. If anyone can show or explain how I’d appreciate it.