- Home /
AutoScale Orthographic Camera
Hi, I need help to setup auto scale orthographic camera. I am new for 2D game development. I have created simple plane and applied texture on it using transparent cutout shader and made it prefab. then i instantiated plane prefab in grid pattern 3x3. I want to change this grid pattern randomly, whenever start my game, grid pattern should be random like (3x4) (4x6)(4x8).so I used random.range but the problem is, I am not able to make that grid on the center of the orthographic camera, whenever my game start, grid doesn't come on the center. I also want it to be auto scale because it doesn't fit on screen resolution because grid is randomly changing (3x3), (3x4), (4x5) I really need to sort out this issue because i have no idea how orthographic camera works.
public int gridWidth =0;
public int gridHeight = 0;
public GameObject facePrefab = null;
void Awake()
{
gridHeigth = Random.range(3,5);
gridWidth = Random.range(3,5);
for (int x = 0; x < gridWidth; x++) {
for (int y = 0; y < gridHeight; y++) {
GameObject g = Instantiate (facePrefab, new Vector3 (x, y, 0), Quaternion.identity)as GameObject;
}
}
}
any help would be appreciated Thanks in advance
Answer by 0mr_ashutosh0 · Dec 11, 2014 at 06:50 PM
public float randomOne;
public float randomTwo;
Void Start()
{
randomOne = Random.Range(3,6);
Camera.main.orthographicSize = (randomOne / Screen.width * Screen.height / 2.0f);
}
not sure. but try this
if there is some type error the just (float) before Random.Range like this (float)Random.Range cuz its int right now.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
orthographic camera 0 Answers
Aquarium like camera 1 Answer
Show squares in the camera 0 Answers
How to save a RenderTexture to a png from a different camera? 1 Answer