How to Make Looping Backgrounds [Unity Tutorial]

  Рет қаралды 102,620

Comp-3 Interactive

Comp-3 Interactive

Күн бұрын

Пікірлер: 77
@qwasd0r
@qwasd0r 3 ай бұрын
This is the perfect tutorial for me, it's both scrolling without moving the camera AND explains a parallax effect. Thank you!
@jocarlbasco994
@jocarlbasco994 3 жыл бұрын
This is useful. I found many tutorials about looping backgrounds but I think this is the easiest way to do.
@Dangerous_Milk
@Dangerous_Milk 2 жыл бұрын
using UnityEngine; public class ScrollingBackground : MonoBehaviour { public float Speed; private float offset; private Material mat; private void Start() { mat = GetComponent().material; } 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 :)
@ShenglanLu
@ShenglanLu 2 жыл бұрын
thank you so much!!!
@indianmultidoer7524
@indianmultidoer7524 Жыл бұрын
thanks brother
@haifameddeb1736
@haifameddeb1736 Жыл бұрын
thank you sooooo much
@Imsorryman
@Imsorryman Жыл бұрын
Life saver.
@FraserBogs
@FraserBogs Жыл бұрын
tnx life saver
@mazingood826
@mazingood826 6 ай бұрын
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!
@MuttleyGames
@MuttleyGames 2 жыл бұрын
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(); 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.
@EnchantedFailure
@EnchantedFailure Жыл бұрын
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..
@scratchguitar
@scratchguitar 2 жыл бұрын
You are the best good sir!!!!! 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!!!
@vishalkhombare
@vishalkhombare 4 жыл бұрын
Great Tut!! But in the end you should have scrolled grass fast and bkg slow , to make it feel more natural I guess.
@mikewestanims5785
@mikewestanims5785 3 жыл бұрын
I absolutely agree, it's how it's done in the industry too. Or else it makes it feel like the player isn't running that fast.
@xCratuss
@xCratuss 3 жыл бұрын
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.
@vaibhavkrkm
@vaibhavkrkm 5 ай бұрын
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)
@gameswithzeta6779
@gameswithzeta6779 Жыл бұрын
damn this is waaay better than other methods Ive seen.
@rollingstonesonroad
@rollingstonesonroad 4 жыл бұрын
Incredible tutorial. Learnt something new. Keep up.
@Dom-wv9zm
@Dom-wv9zm 3 жыл бұрын
Great tutorial, so cool. Thanks man!
@SpaceGuy2023
@SpaceGuy2023 Жыл бұрын
Phenomenal! thanks mate. helped me put a moving background of clouds/sky on the flappybird copycat game im making for fun!
@bigtimecool9635
@bigtimecool9635 2 жыл бұрын
yes!! this was exactly what i was looking for, thank you!!!!
@Emilis2023
@Emilis2023 Жыл бұрын
Worked like a charm, thanks!
@themofo
@themofo 2 жыл бұрын
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
@ig9652
@ig9652 Жыл бұрын
very helpful, thanks for this
@a.....a-n2i
@a.....a-n2i 4 ай бұрын
Nice video very useful
@mrguy1234_5
@mrguy1234_5 4 ай бұрын
Im trying to make a 2d game but I cant get the box collider to work so my character keeps falling through the map if you know a fix please help
@semihguner1
@semihguner1 2 жыл бұрын
This helped me a lot! Thanks
@pencilgamesstudio9330
@pencilgamesstudio9330 4 жыл бұрын
Nice tutorial, better than using transform with spaw point and etc Keep going ;)
@TheOnlySane
@TheOnlySane Жыл бұрын
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?
@darkflame2848
@darkflame2848 2 жыл бұрын
Appriciated bro
@daniel_druziki
@daniel_druziki 2 жыл бұрын
Thank you so much!!!
@nich_788
@nich_788 9 ай бұрын
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.
@demetrekalandarishvili2600
@demetrekalandarishvili2600 Жыл бұрын
Great tutorial. Grass should have been faster and background slower though.
@OskGame
@OskGame 4 жыл бұрын
nice tutorial , thanks
@Osoclever
@Osoclever 8 ай бұрын
Thank you
@marabottojem6649
@marabottojem6649 3 жыл бұрын
Awesome, yet simple video! Thanks.
@LEARNWITHABEGINNER
@LEARNWITHABEGINNER 5 ай бұрын
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 ?
@nikscarr
@nikscarr 3 жыл бұрын
Thanks mate
@amirhusain6834
@amirhusain6834 3 жыл бұрын
Why the word 'Range' and 'MonoBehaviour' not green?
@TheCoolestCube
@TheCoolestCube 4 ай бұрын
Does this code only work for flat 2d images and not 3d scenes?
@umarra9191
@umarra9191 3 жыл бұрын
Hey sir, very very informative video. Sir plz make a video how we can handle animation through script.
@nofilkhan3164
@nofilkhan3164 2 жыл бұрын
Why on earth on youtube nobody tells ,why are doing certain things ,i mean press this press that .type this and type that and it will work ,
@hi_im_kuro9665
@hi_im_kuro9665 3 жыл бұрын
thanks
@PaulVRo
@PaulVRo Жыл бұрын
I can;t add the image as a material, why?
@makeru4024
@makeru4024 Жыл бұрын
somehow the background appears to be up front and i cant see the UI elements anymore. How do i fix this?
@faizanpers
@faizanpers 7 ай бұрын
how to scroll smaller individual objects that cannot be stretched till boundaries like clouds
@seanholmes7482
@seanholmes7482 3 жыл бұрын
Every time I try to adjust my background image on Unity to x = 90 and y = -180 the whole pictures turns dark. Why?
@harleywaters156
@harleywaters156 3 жыл бұрын
Make sure you've disabled receive shadow, and change material shader to unlit/texture
@seanholmes7482
@seanholmes7482 3 жыл бұрын
@@harleywaters156 , do you have other videos on Unity? The object I work with keeps falling.
@gamingsih8854
@gamingsih8854 Жыл бұрын
Hey bro.. I've already follow your tutorial. But,on the process to enter play mode. I got an error like this " Material ..... (Instance) with shader 'unlit/texture' doesn't have a texture property 'MainTex' UnityEngine. material:Set TextureOffset (string, UnityEngine. Vector 2)." Iam new in this things and very noob. Hopefully you or anybody can help me with my problem.
@EnchantedFailure
@EnchantedFailure Жыл бұрын
did you put the underscore before it? I had this issue too, solved it when I realised I was missing the underscore. it should be "_MainTex", looking at your error I have a feeling you did miss it..
@alexhomola6927
@alexhomola6927 2 ай бұрын
@@EnchantedFailure im a bit late but yeah I had the same issue but then I realized
@daniel_druziki
@daniel_druziki 2 жыл бұрын
does this work for mobile game?
@IAmScarab
@IAmScarab 3 жыл бұрын
Looks like a great scrolling effect but how would you make this scroll with the players movement instead off continuosly?
@Finlzz
@Finlzz 3 жыл бұрын
Dani has a good tutorial for what you want
@trungthanhbp
@trungthanhbp 4 жыл бұрын
Nice assets, can i ask where you get it ^^
@comp3interactive
@comp3interactive 4 жыл бұрын
Sorry man. This was just a royalty free image I came across
@davidreddick5244
@davidreddick5244 3 жыл бұрын
Has anyone else tried this method, built as webgl, and tried running on mobile? The texture seems to mess up and stretch rather than repeat as expected.
@PeteThePangolin
@PeteThePangolin 2 жыл бұрын
Any fix? I ran into this
@EvanPilb
@EvanPilb Жыл бұрын
​@@PeteThePangolin Fix: don't use webgl, don't use webgl on mobile
@vineq9367
@vineq9367 2 жыл бұрын
My background doesn´t move (3d game) Help.
@manolisroutsis5227
@manolisroutsis5227 Жыл бұрын
can youi send me the image which you used to tutorial i need the exact same one
@ErcumentCozerx
@ErcumentCozerx 2 жыл бұрын
I did but my character is 2d but plane object is 3d so my character is falling down from the ground that I made
@kabhes9040
@kabhes9040 2 жыл бұрын
Okay but if the character doesn't move the background doesn't ether.
@TheEeryTeacher
@TheEeryTeacher Жыл бұрын
didn't work for me.. i think its because i need the camera to scroll on its own and not when the player is moving
@MuhammadQasim-lg2bs
@MuhammadQasim-lg2bs 2 жыл бұрын
Doesn't work for me.
@ippulnugroho
@ippulnugroho Жыл бұрын
how about vertical?
@inkkles
@inkkles 10 ай бұрын
on 5:12 you would just put the offset on the y instead of the x, and make x 0 i.e. mat.SetTextureOffset("_MainTex", new Vector2(0, offset)); //notice the 0 and offset got swapped to make it vertical
@fedbobgamingfeddroidgaming764
@fedbobgamingfeddroidgaming764 Жыл бұрын
Didn't work
@Nikelover.warspear
@Nikelover.warspear 4 ай бұрын
Doesn't work
@Straw-Hat-Shorts
@Straw-Hat-Shorts 4 ай бұрын
the image is streched how do i make it unstreched
How to make AWESOME Scene Transitions in Unity!
19:45
Brackeys
Рет қаралды 966 М.
Infinite Parallax Scrolling Background - Unity 2D Complete Tutorial
7:24
Game Code Library
Рет қаралды 12 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Making a Background BEAUTIFUL (My full process)
8:01
Lost Relic Games
Рет қаралды 106 М.
Parallax Infinite Scrolling Background in Unity
17:11
Code Monkey
Рет қаралды 150 М.
2D Field of View [Unity Tutorial]
18:08
Comp-3 Interactive
Рет қаралды 16 М.
How to play random animations [Unity Tutorial]
7:36
Comp-3 Interactive
Рет қаралды 22 М.
TOUCH CONTROLS in Unity!
16:09
Brackeys
Рет қаралды 1,3 МЛН
MELEE COMBAT in Unity
21:07
Brackeys
Рет қаралды 1,6 МЛН
Make Your MAIN MENU Quickly! | Unity UI Tutorial For Beginners
10:32
Unity 2D PARALLAX EFFECT Tutorial | Endless Scrolling Background
6:55