Zenternion
Zenternion
CC#
Created by Zenternion on 1/2/2023 in #help
❔ UNITY When I manually execute 2 functions it works but not when executing them from 1 function.
When I run Initialize() it only works the 2ND TIME (First time only runs DestroyCities(), Second time runs both()). But If I do DestroyCities() and then GenerateCities() manually it works EVERY TIME.
public void Initialize()
{
DestroyCities();
GenerateCities();
}

public void GenerateCities()
{
Cities cities = new Cities();
cities = cities.CreateJSON();

int i = 0;

foreach (feature cityData in cities.features)
{.......

public void DestroyCities()
{
for (int
i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go)); //destroys thing (WORKS)
}
}
public void Initialize()
{
DestroyCities();
GenerateCities();
}

public void GenerateCities()
{
Cities cities = new Cities();
cities = cities.CreateJSON();

int i = 0;

foreach (feature cityData in cities.features)
{.......

public void DestroyCities()
{
for (int
i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go)); //destroys thing (WORKS)
}
}
Editor:
public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
cityGeneration.Initialize();
}
}

if (GUILayout.Button("Initialize Cities"))
{
cityGeneration.Initialize();
}

if (GUILayout.Button("Generate Cities"))
{
cityGeneration.GenerateCities();
}

if (GUILayout.Button("Destroy Cities"))
{
cityGeneration.DestroyCities();
}

DrawSettingsEditor(cityGeneration.shapeSettings, cityGeneration.OnShapeSettingsUpdated, ref cityGeneration.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(cityGeneration.citySettings , cityGeneration.OnCitySettingsUpdated , ref cityGeneration.citySettingsFoldout , ref cityEditor);
}
public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
cityGeneration.Initialize();
}
}

if (GUILayout.Button("Initialize Cities"))
{
cityGeneration.Initialize();
}

if (GUILayout.Button("Generate Cities"))
{
cityGeneration.GenerateCities();
}

if (GUILayout.Button("Destroy Cities"))
{
cityGeneration.DestroyCities();
}

DrawSettingsEditor(cityGeneration.shapeSettings, cityGeneration.OnShapeSettingsUpdated, ref cityGeneration.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(cityGeneration.citySettings , cityGeneration.OnCitySettingsUpdated , ref cityGeneration.citySettingsFoldout , ref cityEditor);
}
20 replies
CC#
Created by Zenternion on 12/31/2022 in #help
❔ 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);
}
}
}
2 replies
CC#
Created by Zenternion on 11/20/2022 in #help
❔ UNITY Vector3 not applying
int cPop = Mathf.RoundToInt(((tCity.POP_MIN + tCity.POP_MAX) ?? 0) / 2.0f); //tCity just holds the data of the city

Object cityToUse;

float popMult;
if (cPop <= 500000 && cPop > 0)
{cityToUse = cityTo500K; popMult = cPop / 1000000;}
else if (cPop <= 1000000 && cPop > 500000)
{cityToUse = cityTo1M; popMult = cPop / 1000000;}
else if (cPop > 1000000)
{cityToUse = cityToRest; popMult = (cPop / 10000000) + 1;}
else
{cityToUse = cityTo500K; popMult = 0.3f;}//

if (popMult < 0.3) popMult = 0.3f;

//other code
//........

Vector3 multiplier = new Vector3(popMult * shapeSettings.radius, popMult * shapeSettings.radius, popMult * shapeSettings.radius);
do {
cityMeshGameObject.transform.localScale = multiplier;
} while(cityMeshGameObject.transform.localScale != multiplier);
int cPop = Mathf.RoundToInt(((tCity.POP_MIN + tCity.POP_MAX) ?? 0) / 2.0f); //tCity just holds the data of the city

Object cityToUse;

float popMult;
if (cPop <= 500000 && cPop > 0)
{cityToUse = cityTo500K; popMult = cPop / 1000000;}
else if (cPop <= 1000000 && cPop > 500000)
{cityToUse = cityTo1M; popMult = cPop / 1000000;}
else if (cPop > 1000000)
{cityToUse = cityToRest; popMult = (cPop / 10000000) + 1;}
else
{cityToUse = cityTo500K; popMult = 0.3f;}//

if (popMult < 0.3) popMult = 0.3f;

//other code
//........

Vector3 multiplier = new Vector3(popMult * shapeSettings.radius, popMult * shapeSettings.radius, popMult * shapeSettings.radius);
do {
cityMeshGameObject.transform.localScale = multiplier;
} while(cityMeshGameObject.transform.localScale != multiplier);
2 replies
CC#
Created by Zenternion on 11/6/2022 in #help
apply height to sphere UNITY
how do I know on which vertices I apply which pixel of the height map (of earth)
1 replies
CC#
Created by Zenternion on 10/28/2022 in #help
Scale not changing UNITY
The mesh localScale doesent change except if I remove all of the objects first and run it again which I try to do in the code but doesent work.
Object cityMesh = Object.Instantiate(cityToUse, cityPosition, cityRotation, cityObject.transform);
cityMesh.name = $"City Mesh {i + 1}";
GameObject cityMeshGameObject = GameObject.Find(cityMesh.name);

cityMeshGameObject.transform.localScale *= shapeSettings.radius;
Object cityMesh = Object.Instantiate(cityToUse, cityPosition, cityRotation, cityObject.transform);
cityMesh.name = $"City Mesh {i + 1}";
GameObject cityMeshGameObject = GameObject.Find(cityMesh.name);

cityMeshGameObject.transform.localScale *= shapeSettings.radius;
shapeSettings.radius = 10
1 replies
CC#
Created by Zenternion on 10/26/2022 in #help
Scale not changing UNITY
The mesh localScale doesent change except if I remove all of the objects first and run it again which I try to do in the code but doesent work.
Object cityMesh = Object.Instantiate(cityToUse, cityPosition, cityRotation, cityObject.transform);
cityMesh.name = $"City Mesh {i + 1}";
GameObject cityMeshGameObject = GameObject.Find(cityMesh.name);

cityMeshGameObject.transform.localScale *= shapeSettings.radius;
Object cityMesh = Object.Instantiate(cityToUse, cityPosition, cityRotation, cityObject.transform);
cityMesh.name = $"City Mesh {i + 1}";
GameObject cityMeshGameObject = GameObject.Find(cityMesh.name);

cityMeshGameObject.transform.localScale *= shapeSettings.radius;
shapeSettings.radius = 10
1 replies
CC#
Created by Zenternion on 10/18/2022 in #help
InvalidCastException Specified cast is not valid.
public void DestroyCities() //102
{ //103
foreach(GameObject go in transform) //104
{ //105
do {
StartCoroutine(DestroyFastly(go));
} while(go != null);
}
}
public void DestroyCities() //102
{ //103
foreach(GameObject go in transform) //104
{ //105
do {
StartCoroutine(DestroyFastly(go));
} while(go != null);
}
}
Why is this happening
42 replies
CC#
Created by Zenternion on 10/16/2022 in #help
Add MonoBehaviour to object through script UNITY
Is there a way to add a monobehaviour to an object through a different script.
8 replies
CC#
Created by Zenternion on 10/15/2022 in #help
UNITY Get Quaterion to rotate towards Object
How do I get (return type) a quaternion to rotate towards an object
7 replies