I have a scene with multiple GameObjects with x-y-z position. I'm in 2D so the z is not used.
For now, I worked with the resolution 1024/768 and when I add a GameObject like :
GameObject star = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Vector3 position = new Vector3 (x, y, z);
star.transform.localPosition = position;
It's ok, the GameObject is in the right position on my scene.
But nox, I'm trying to change the resolution (1920/1080) and all my GameObjects are moved far on the top right, out of my camera.
What's the problem ? How can I fix this ?
For me, when I change the resolution, the 0-0-0 change for my GameObjects....and something weird, If my GameObject has a LineRenderer with positions, they are good on all resolutions...
Edit : This is the function I use for generate my GameObjects, it's a galaxy generator :
for(int i = 0; i < numberOfStars; i++) {
bool checkPosition = false;
while (!checkPosition) {
// Choose a distance from the center of the galaxy.
float distance = Random.Range(5.0f, (float) galaxySize / 2 - 5);
// Choose an angle between 0 and 2 * PI.
float angle = Random.Range(0.0f, 100.0f) * 2 * Mathf.PI;
Vector3 position = new Vector3 (Mathf.Cos (angle) * distance, Mathf.Sin(angle) * distance, 9);
if (! Physics.CheckSphere(position, 1)) {
GameObject star = GameObject.CreatePrimitive(PrimitiveType.Sphere);
star.AddComponent<SolarSystem>();
star.name = i + "_" + PlanetNameGenerator.GenerateName();
star.GetComponent<SolarSystem>().name = i + "_" + PlanetNameGenerator.GenerateName();
star.transform.parent = GameObject.Find ("Targets").transform;
// On change le scale en random
float randomScale = Random.Range (0f, 0.5f);
star.transform.localScale += new Vector3(randomScale,randomScale,randomScale);
star.transform.localPosition = position;
star.tag = "SolarSystem";
checkPosition = true;
}
}
}
This is the scene I see in 1024/768, with my Sphere GameObjects and in pink LineRenderer between them :
This is what I see in 1920/1080, LineRenderer are always in the same position, but GameObjects move away :