1
\$\begingroup\$

I have an area say a x b of cells. actually I render every single cell in this matrix with a tile representing floor, wall, etc. What I'm trying to achieve it to replace this tiling system with a unique tile covering the whole a x b area.

I tried to play with creating a single GameObject and then adding a SpriteRenderer component with the base idea to stick in a sprite with desired size so that the image (whatever it is) gets stretched to fit it but apparently all the suitable fields which could be involved in this are readonly (I considered the rect and the bounds attribute).

In other words I feel like I'd need to attach a SpriteRenderer with a dynamic size based on given dimensions. How could I reach this goal?

\$\endgroup\$
  • 3
    \$\begingroup\$ Have you looked into using the localScale fields of the transform component to do the stretching you need? \$\endgroup\$ – DMGregory Apr 30 '16 at 14:09
1
\$\begingroup\$

There are multiple ways to achieve that, simple one is:

  1. Set scale of the sprite to width = a * tileWidth, height = b * tileHeight
  2. Set draw mode to Tiled or Sliced if you have some borders https://docs.unity3d.com/ScriptReference/SpriteRenderer-drawMode.html
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

You may need to generate your own Mesh dynamically and use a MeshRenderer.

Which may require building your own texture atlas with all the tile textures.

This would give you full control over the shape, size and texture coordinates of your custom sprites.

http://docs.unity3d.com/ScriptReference/Mesh.html

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.