I have a problem when im trying to set scale and coordinates of my objects in code. In my game i need to place objects in random way and they need to stay block by block and without space between (like on reference image). But when i do my code, they stay on large distance and with strange scale. I would be very grateful if you could help me with this thing. And i place oobjects in worldspace, not in ui.
My game
reference
Here is my code:
screen_bounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
float screen_width = screen_bounds.x * 2;
float screen_height = screen_bounds.y * 2;
var border_left = Instantiate(borderObject);
border_left.transform.localScale = new Vector3(1, screen_bounds.y*2, 1);
border_left.transform.position = new Vector3(-1 * screen_bounds.x - border_left.transform.localScale.x/2, 0, 0);
var border_right = Instantiate(borderObject);
border_right.transform.localScale = new Vector3(1, screen_bounds.y * 2, 1);
border_right.transform.position = new Vector3(screen_bounds.x + border_right.transform.localScale.x / 2, 0, 0);
var border_top = Instantiate(borderObject);
border_top.transform.position = new Vector3(0, screen_bounds.y, 0);
border_top.transform.Rotate(0, 0, 90);
for (int i = 1; i < 6; i++)
{
var block = Instantiate(block_types[Random.Range(0, block_types.Length)]);
block.transform.localScale = new Vector3(screen_width / 5 / 2, screen_width / 5 / 2, screen_width / 5 / 2);
block.transform.position = new Vector3(-1 * screen_bounds.x + block.transform.localScale.x * i * 2, 4, 0);
}
I think that issue related with bad scaling. But i dont understand how to do it in right way
Даниил Снадкин is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.