C
C#2y ago
Zenternion

❔ UNITY Code only fully executes after running it another time

When running GenerateCities() it only does DestroyCities() and CreateCountryColors() before stopping, but when I run it again it executes the whole code. No errors
public void DestroyCities()
{
for (int i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go));
}

/*for (int i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go));
}*/
}

private IEnumerator DestroyFastly(GameObject go)
{
yield return new WaitForSeconds(0);
DestroyImmediate(go, false);
}
public void DestroyCities()
{
for (int i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go));
}

/*for (int i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go));
}*/
}

private IEnumerator DestroyFastly(GameObject go)
{
yield return new WaitForSeconds(0);
DestroyImmediate(go, false);
}
public static class CreateCountryColors
{
private static Color[] colors = {
Color.blue,
Color.cyan,
Color.green,
Color.magenta,
Color.red,
Color.yellow
};

private static int colorIndex = 0;

public static void Create(string path)
{
Countries countries = new Countries();
countries = countries.CreateJSON();

foreach (feature countryData in countries.features)
{
string code = countryData.properties.ISO_A2.ToUpper();

Material countryMaterial = new Material(Shader.Find("HDRP/Lit"));
countryMaterial.color = colors[colorIndex];

if (colorIndex == colors.Length - 1)
colorIndex = 0;
else
colorIndex++;

do {
AssetDatabase.CreateAsset(countryMaterial, $"{path}/{code}.mat");
} while (AssetDatabase.LoadAssetAtPath<Material>($"{path}/{code}.mat") == null);
}
}
}
public static class CreateCountryColors
{
private static Color[] colors = {
Color.blue,
Color.cyan,
Color.green,
Color.magenta,
Color.red,
Color.yellow
};

private static int colorIndex = 0;

public static void Create(string path)
{
Countries countries = new Countries();
countries = countries.CreateJSON();

foreach (feature countryData in countries.features)
{
string code = countryData.properties.ISO_A2.ToUpper();

Material countryMaterial = new Material(Shader.Find("HDRP/Lit"));
countryMaterial.color = colors[colorIndex];

if (colorIndex == colors.Length - 1)
colorIndex = 0;
else
colorIndex++;

do {
AssetDatabase.CreateAsset(countryMaterial, $"{path}/{code}.mat");
} while (AssetDatabase.LoadAssetAtPath<Material>($"{path}/{code}.mat") == null);
}
}
}
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.