How to fit rectangles to sprites?

I’m using C# scripting and I want to create rectangles that have the exact size and position of a sprite of my choice in the scene. I will then use these rectangles in my GUI buttons.

This is for a turn-based game where the sprite is a square tile. I want the rectangle on top so players can click when they want to move there.

I’ve tried getting the position of the sprites using Vector3 variables which I stored and calculated in other scripts but when I create the button it doesn’t appear where the sprite/tile is. I also use

(Renderer.bounds.max.x - Renderer.bounds.min.x)

to try and get the size of the sprite but it ends up too small.


Try using unity4.6 beta.
It has all these functionalities in components ->ui->Button.
This will solve your issue.
Even anchors can be applied.