- Home /
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.
Thanks.
Answer by alap soni · Oct 06, 2014 at 08:37 AM
Try using unity4.6 beta. It has all these functionalities in components ->ui->Button. This will solve your issue. Even anchors can be applied.
I appreciate the response and suggestion but I'm interested in more ways to accomplish what I need.