ok, so i am making a script for my game that generates the composition of a silicate planet. it is not great code, as i am pretty new to coding, but here it is:
using UnityEngine;
public class silicateComposition : MonoBehaviour
{
public GameObject noise;
public int silicone;
public int ironOxide;
public int iron;
public int oxygen;
public int aluminium;
public int calcium;
public int sodium;
public int potassium;
public int magnesium;
// Start is called before the first frame update
void Start()
{
Debug.Log("was run");
int seed = noise.GetComponent<mapGenerator>().seed;
Debug.Log("go2");
ironOxide = seed / 15;
iron = seed / 100;
oxygen = seed / 13;
aluminium = seed / 132;
calcium = seed / 104;
sodium = seed / 115;
potassium = seed / 193;
magnesium = seed / 294;
int total = iron + ironOxide + oxygen + aluminium + calcium + sodium + potassium + magnesium;
Debug.Log(ironOxide);
Debug.Log(iron);
Debug.Log(oxygen);
Debug.Log(aluminium);
Debug.Log(calcium);
Debug.Log(sodium);
Debug.Log(potassium);
Debug.Log(magnesium);
Debug.Log(total);
if (total > 85)
{
int t = total - 85;
total = total - t;
int iod = ironOxide.ToString().Length;
int id = iron.ToString().Length;
int od = oxygen.ToString().Length;
int ad = aluminium.ToString().Length;
int sd = sodium.ToString().Length;
int pd = potassium.ToString().Length;
int md = magnesium.ToString().Length;
int cd = calcium.ToString().Length;
Debug.Log(iod);
if (iod >= 2)
{
int iod2 = iod;
int temp = 0;
while (iod > 2)
{
iod = iod - 1;
temp = temp + 1;
}
iod = temp;
int tens = 1000000;
temp = 0;
while (tens.ToString().Length > iod)
{
tens = tens / 10;
}
if (tens = 1)
{
tens = 10;
}
ironOxide = ironOxide / tens;
}
silicone = 100 - total;
if (silicone < 0)
{
silicone = 0;
}
}
}
}
so basically it generates a random percentage based on real life proportions and a seed. Also i have only coded the iron Oxide loop, so I can figure out how to do it before i do it with every element.
It does work, until it hits the if total is above 85 if statement. then unity just freezes. I do not understand why, as I have poured over the code for 2 days now and I'm losing my sanity. thank you for any help.
Aucun commentaire:
Enregistrer un commentaire