[2D]Size of an object + align on grid


First, I want to know if it’s possible to see the object’s size directly in unity, and if yes, if we can change it directly. I know we can get it with renderer.bounds.size, but it would help if I could do that directly, like for the position/rotation/scale.

Secondly, I want to know if it’s possible to align objects to the grid, in function of an object’s size.
It would REALLY help me for the scenes’creation.

Thanks. (and sorry for the bad english).

What do you mean by getting the size directly? I would say renderer.bounds.size and transform.localScale are about as direct as it gets. Ex:

Vector3 scale = transform.localScale;

As for the grid: Here are the steps I would take:

1: Get the selected objects x and y position.

2: Take off the remainder from the grid size on both the width and the height:

xPos = objPos.x - objPos.x % gridSpacing (Same with the yPos)

3: Move the object to it’s new locked xPos and yPos

You are going to have to execute these things in edit mode.

I tried some stuff, and it doesn’t work.

I can easily change position with this.transform.position = new Vector2 (x,y);
but it doesn’t work with scale or size.
When I try this : renderer.bounds.size = new Vector2 (x, y);
I have the error :

error CS1612: Cannot modify a value
type return value of
Consider storing the value in a
temporary variable

I can assign it, but just read it.

Someone know how I can change the size of an object ?