- Home /
2D - How to make sprites repeat tiles?
I recently started using Unity in an attempt to make a game prototype. I initially made a version of the game I'm making in Game Maker, but I expected I could make a better version in Unity. As I've been trying to migrate things over, I ran into probably the stupidest problem. I'm trying to apply sprites to objects, and to limit the number of objects (a few large ones rather than a whole bunch arranged in a grid), I'm trying to use box colliders as well as any others I find necessary. But what I'm having trouble with is getting the graphic to look like a repeating texture rather one that scales with the size of the object. The only component I've found to display 2D sprites is the Sprite Renderer. I tried changing the Sprite into a texture, but that's apparently incompatible with Sprite Renderers. I also tried adding a bit of code to change the sprite to "repeatable", but that doesn't seem to do anything.
void Update () { renderer.material.mainTexture.wrapMode = TextureWrapMode.Repeat; }
If there are any other tools that can solve this issue, I would appreciate any suggestions including any code to use preferably in C# or how to execute the code.
Answer by zvasconcelos · Dec 30, 2018 at 01:11 PM
I know this is an old question, but in case someone still in doubt about this topic, you can set you sprite's "Wrap mode" to "repeat". This will do the trick.
This should be the accepted answer, it works perfectly.
Answer by ShichiNoBushi · Mar 09, 2015 at 11:42 AM
edit: previous answer apparently removed
I'm sorry, but your answer doesn't help much because it seems to be about animation. What I need to happen is to have a texture create repeating tiles on the environment. I already imported the sprites as images into Unity, and they automatically became Sprite 2Ds. My problem is that as I adjust the size of the objects they're applied to, they scale with the size rather than staying the same and crating copies.
Answer by dval · Jan 08, 2016 at 02:01 AM
You could sort of cheat by having a parent gameobject with a RectTransform and a UI.GridLayoutGroup component attached. Then, your sprite would need a UI.LayoutElement attached to it. Then just fill the layout with sprite instances.
It would be a pain to manage without a script in the large scale. But for small groups that change size, it works nice. Doesn't add a lot of overhead either. Unity seems to be ok with the re-use.
Answer by ly202009 · May 26 at 04:09 PM
@ShichiNoBushi This is a really old post but I had some trouble around this so just leaving some stuff. Set the sprite settings to something like this:
https://answers.unity.com/storage/temp/196801-screenshot-2022-05-26-094951.png
Then create a gameobject with a sprite renderer that shows this sprite, and put a collider on it, in my case, my sprite is a metal box. Make sure to crop out any blank space on your sprite in the sprite editor. Set the scale of the gameobject to whatever you want the repeating sprite to be the size of. In the collider, turn on Auto Tiling. Set the Draw Mode of the Sprite Renderer to Tiled. Now your gameobject settings should look something like this:
https://answers.unity.com/storage/temp/196802-screenshot-2022-05-26-095422.png
To change the size, DON'T ALTER THE SCALE, alter the width and the height in the sprite renderer and it'll repeat the sprite. Hope this helps!
Your answer
Follow this Question
Related Questions
Sprite rendering texture as one solid color 1 Answer
Tilemap: Resizing Tiles? 1 Answer
loading sprite from atlas in script 4 Answers
How change sprite animation texture?? 2 Answers
Unity Adds Antialiasing to Texture 2 Answers