I have a spawner outside of camera, and I want it to always be at that distance from the screen edge.
But if the player have a different screen size(for example, he has an ipad) the spawner will be inside the camera because the camera will be wider.
Is there a way to set up an anchor or something similar with the camera so a gameobject is always at a certain position from the camera?
You could probably set the spawner as a child of the camera (so it moves with the camera). Then, to get a position that’s just “off screen”, you might use something like this on the spawner.
var leftCenter = Camera.main.ViewportToWorldPoint(new Vector3(0, 0.5f, 0));
transform.position = new Vector3(leftCenter.x - 1.0f, leftCenter.y, 0);
The trick is in the ViewportToWorldPoint() method which represent the lower-left corner of the visible screen as 0,0 and the upper right as 1,1. So the above finds the world position of the left-edge of the screen (the 0 in X) and the mid-point in the vertical (the 0.5 in the Y).
Then, it sets the transform of the gameobject (presumably, the spawner) to that same point - except 1 game unit to the “left” - or 1 unit “off of the screen”.
The above is typed directly into the forum and untested, but should give you the idea…