Quantcast
Channel: Latest Questions by RoboticSarcasm
Viewing all articles
Browse latest Browse all 40

Issue with seed-based generation [C#]

$
0
0
Hello everybody, after tinkering around with seed-based generation, i have run into an issue. I use part of a float and turn it into a string, but the string always becomes something along the lines of 2.090868e+18 which for me is useless, because i use a float to generate boxes in a specific location. After a couple of boxes being spawned, i obviously run into the problem of reaching a letter instead of a number, and i have not a single clue as of how i can fix this. I hope you guys do. Code: using UnityEngine; using System.Collections; using System.Text; using System.IO; public class gameSystems : MonoBehaviour { public Transform boxToSpawn; public float timeLeft; public int score; public AudioClip pickupAudio; /////////BOX SPAWNING VARIABLES///////////// public float generatedSeed; public string seedTempString; public char seedChar; public string seedCharString; public int boxesGenerated; public float boxSpawnPos; public float boxPreviousSpawnPos; void Awake() { GameObject.Find("gameSystems").SendMessage("SaveGame", SendMessageOptions.DontRequireReceiver); DontDestroyOnLoad(transform.gameObject); boxesGenerated = 1; GenerateSeed(); CalculateSpawnPos(); Time.timeScale = 1; } void AddScore(int scoreAdded) { audio.PlayOneShot(pickupAudio); score += scoreAdded; CalculateSpawnPos(); { GameObject.Find("gameSystems").SendMessage("SaveGame", SendMessageOptions.DontRequireReceiver); } } void GenerateSeed() { generatedSeed = Random.Range(1000000000000000000, 10000000000000000000); } void CalculateSpawnPos() { if (boxSpawnPos == 0) { boxSpawnPos = 1; } if (boxSpawnPos == boxPreviousSpawnPos) { boxSpawnPos += 1; } spawnBox(); } void FixedUpdate() { seedTempString = generatedSeed.ToString(); seedChar = seedTempString[boxesGenerated]; seedCharString = seedChar.ToString(); boxSpawnPos = float.Parse(seedCharString); timeLeft -= Time.deltaTime; if (timeLeft <= 0) { Application.LoadLevel(Application.loadedLevel); } } void spawnBox() { boxesGenerated += 1; if (boxSpawnPos == 1) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn1").transform.position, Quaternion.identity); } if (boxSpawnPos == 2) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn2").transform.position, Quaternion.identity); } if (boxSpawnPos == 3) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn3").transform.position, Quaternion.identity); } if (boxSpawnPos == 4) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn4").transform.position, Quaternion.identity); } if (boxSpawnPos == 5) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn5").transform.position, Quaternion.identity); } if (boxSpawnPos == 6) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn6").transform.position, Quaternion.identity); } if (boxSpawnPos == 7) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn7").transform.position, Quaternion.identity); } if (boxSpawnPos == 8) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn8").transform.position, Quaternion.identity); } if (boxSpawnPos == 9) { Instantiate(boxToSpawn, GameObject.Find("boxSpawn9").transform.position, Quaternion.identity); } boxPreviousSpawnPos = boxSpawnPos; } } Thank you for taking the time to help me, and i hope i can at some point help you. Greetings, Roel Zwakman / RoboticSarcasm

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>