1
votes

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 : enter image description here

This is what I see in 1920/1080, LineRenderer are always in the same position, but GameObjects move away : enter image description here

1
Can you provide more code? also provide whether you are using a perspective or orthographic camera, and how are you changing the resolution?AresCaelum
More code like what ? I'm using a perspective camera, and I change the resolution in the editor, in the game viewClément Andraud
Show all the code up the point where this is called and the entire function this is in. With what you provided I wouldn't be able to reproduce your error.AresCaelum
I edited with my function for generate all GameObjects, do you want more ? If yes, like what ? :)Clément Andraud
I added 2 screens ;)Clément Andraud

1 Answers

0
votes

The problem was this line :

star.transform.parent = GameObject.Find ("Targets").transform;

I moved the parent out from Canvas, chnage x-y-z positions of "Targets" to 0 et it's ok.