Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Created January 30, 2025 02:52
Show Gist options
  • Save TheCuttlefish/67644927089ab74266bc00e263a2d494 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/67644927089ab74266bc00e263a2d494 to your computer and use it in GitHub Desktop.
Seeds for tile world
private Transform activeMap;
void SwapMap()
{
if (activeMap) activeMap.gameObject.SetActive(false);
int chunkHash = Mathf.Abs((int)transform.position.x * 73856093 ^ (int)transform.position.y * 19349663);
activeMap = maps[seed.Next(chunkHash, maps.Count)]; // Directly store GameObject
activeMap.gameObject.SetActive(true);
transform.localEulerAngles = new Vector3(0, 0, 90 * seed.Next(chunkHash, 4));
}
public class Seed : MonoBehaviour
{
int seed = 1;
public int Next(float _hashKey, int _range)
{
System.Random rand = new System.Random((int)_hashKey + seed); // Using a fixed seed
return( rand.Next(_range) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment