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.
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.
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.
dval
3
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.
@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:
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:
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!