How to Make Looping Backgrounds [Unity Tutorial]

preview_player
Показать описание
#UnityTutorial #Unity3D #Comp3interactive #GameDev In this video we're going to create a super simple but super useful little script which will control an objects texture to force it to loop indefinitely. Perform for endless runner style games like Flappy Bird!!

Join me and learn your way through the Unity Game Engine, the C# language and the Visual Studio editor. Remember, if this video was useful then DROP A LIKE! 👍

🤝 SPONSORED LINKS:

💬 Join the Discord community here:

📱 Find us on social media for more Tips and Tricks:

📱 Play our games for FREE here on Google Play:

Рекомендации по теме
Комментарии
Автор

This is useful. I found many tutorials about looping backgrounds but I think this is the easiest way to do. <3

jocarlbasco
Автор

awesome tutorial! i must say i was about to look for a new video when you came up with 3d objects and planes but im glad im not! it just shows me how these 3d objects that i NEVER used can be useful in 2d. i guess i have a lot to learn.

cratuss
Автор

Incredible tutorial. Learnt something new. Keep up.

rollingstonesonroad
Автор

You are the best good Tried to do this in various ways!!! this is the only one that worked for my at my first try and I'm a total newb!!!

scratchguitar
Автор

Phenomenal! thanks mate. helped me put a moving background of clouds/sky on the flappybird copycat game im making for fun!

SpaceGuy
Автор

yes!! this was exactly what i was looking for, thank you!!!!

bigtimecool
Автор

as a beginner I found this video very helpful and made me figure out how to add a looping background to my project
thank you man!

mazingood
Автор

Nice tutorial, better than using transform with spaw point and etc Keep going ;)

pencilgamesstudio
Автор

Absolutely great tutorial! Here is how to make it even better:
Instead of Unlit-Transparent Cutout, use Unlit Transparent. This will preserve any fade colors and smooth transitions, better using PNGs.
This will cause an issue with the 2D sprites. Anything above layer 0 will render in front of the foreground and below 0 will render behind the backgrounds which is horrible.
To fix this you will need to put code on Start to set the Layer of the 3D planes as they are set to default 0. The Unity Editor does not have a layer select for whatever reason but properties exist :D
Put this in the Start of your scrolling script and create a new Sorting Layer:
var tr = GetComponent<Renderer>();
tr.sortingLayerName = "Forward";
You need to manually create a Forward (or whatever you call it) layer. You can do it from any 2D sprite in the Unity Editor.

On play all layers will be sorted correctly and you will have perfect PNG backgrounds.

MuttleyGames
Автор

Thanks so much!!! You are a lifesaver! I was so annoyed that I wasn't able to use the same way I used in other things like Godot, Pygame, LOVE2D etc, since all of them work on pixels as they are very optimized for 2D… This was feeling way confusing by using 3D object, but I understood by your video easily! (In those, I used to keep two objects and move them together, then moving the first one back to the front as it crosses the screen, but in Unity, i wasnt able to make it smooth)

vaibhavkrkm
Автор

damn this is waaay better than other methods Ive seen.

gameswithzeta
Автор

an additional comment, the plane's Y axis can be 180 rather than -180. A full loop being 360 (exactly double), this means both have the same result. 0 is facing away, 180 in either direction will flip it to the same point. a small thing but hey ho. I can make better sense of it this way so ill do it like this. Great video. Might actually pass my A-level Computer Science now..

EnchantedFailure
Автор

Great Tut!! But in the end you should have scrolled grass fast and bkg slow, to make it feel more natural I guess.

vishalkhombare
Автор

You can actually use a quad instead of a plane. It'll work the same, but there's less vertices so you'll get better performance

themofo
Автор

Great! And now I want to move some objects, controlled by another script, in the exact same speed as the background. How do I do that?

TheOnlySane
Автор

Hey sir, very very informative video. Sir plz make a video how we can handle animation through script.

umarra
Автор

Thank you so much this was very helpful. The only thing I am having trouble with is that the background is covering up my sprites. How do I move the background to the background lol.

nich_
Автор

Hi ty for this tut but I use a blurry image and when there is the transition, you can see it and looks ugly and not smooth. How can I fix that ?

LEARNWITHABEGINNER
Автор

using UnityEngine;

public class ScrollingBackground : MonoBehaviour
{
public float Speed;

private float offset;
private Material mat;



private void Start()
{
mat =
}


void Update()
{

offset += (Time.deltaTime * Speed) / 10;
mat.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}
}

Here's the code, if u r too lazy to write it yourself :)

Dangerous_Milk
Автор

Why the word 'Range' and 'MonoBehaviour' not green?

amirhusain