This is the perfect tutorial for me, it's both scrolling without moving the camera AND explains a parallax effect. Thank you!
@jocarlbasco9943 жыл бұрын
This is useful. I found many tutorials about looping backgrounds but I think this is the easiest way to do.
@Dangerous_Milk2 жыл бұрын
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 :)
@ShenglanLu2 жыл бұрын
thank you so much!!!
@indianmultidoer7524 Жыл бұрын
thanks brother
@haifameddeb1736 Жыл бұрын
thank you sooooo much
@Imsorryman Жыл бұрын
Life saver.
@FraserBogs Жыл бұрын
tnx life saver
@mazingood8266 ай бұрын
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!
@MuttleyGames2 жыл бұрын
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 Жыл бұрын
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..
@scratchguitar2 жыл бұрын
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!!!
@vishalkhombare4 жыл бұрын
Great Tut!! But in the end you should have scrolled grass fast and bkg slow , to make it feel more natural I guess.
@mikewestanims57853 жыл бұрын
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.
@xCratuss3 жыл бұрын
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.
@vaibhavkrkm5 ай бұрын
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 Жыл бұрын
damn this is waaay better than other methods Ive seen.
Phenomenal! thanks mate. helped me put a moving background of clouds/sky on the flappybird copycat game im making for fun!
@bigtimecool96352 жыл бұрын
yes!! this was exactly what i was looking for, thank you!!!!
@Emilis2023 Жыл бұрын
Worked like a charm, thanks!
@themofo2 жыл бұрын
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 Жыл бұрын
very helpful, thanks for this
@a.....a-n2i4 ай бұрын
Nice video very useful
@mrguy1234_54 ай бұрын
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
@semihguner12 жыл бұрын
This helped me a lot! Thanks
@pencilgamesstudio93304 жыл бұрын
Nice tutorial, better than using transform with spaw point and etc Keep going ;)
@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?
@darkflame28482 жыл бұрын
Appriciated bro
@daniel_druziki2 жыл бұрын
Thank you so much!!!
@nich_7889 ай бұрын
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 Жыл бұрын
Great tutorial. Grass should have been faster and background slower though.
@OskGame4 жыл бұрын
nice tutorial , thanks
@Osoclever8 ай бұрын
Thank you
@marabottojem66493 жыл бұрын
Awesome, yet simple video! Thanks.
@LEARNWITHABEGINNER5 ай бұрын
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 ?
@nikscarr3 жыл бұрын
Thanks mate
@amirhusain68343 жыл бұрын
Why the word 'Range' and 'MonoBehaviour' not green?
@TheCoolestCube4 ай бұрын
Does this code only work for flat 2d images and not 3d scenes?
@umarra91913 жыл бұрын
Hey sir, very very informative video. Sir plz make a video how we can handle animation through script.
@nofilkhan31642 жыл бұрын
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_kuro96653 жыл бұрын
thanks
@PaulVRo Жыл бұрын
I can;t add the image as a material, why?
@makeru4024 Жыл бұрын
somehow the background appears to be up front and i cant see the UI elements anymore. How do i fix this?
@faizanpers7 ай бұрын
how to scroll smaller individual objects that cannot be stretched till boundaries like clouds
@seanholmes74823 жыл бұрын
Every time I try to adjust my background image on Unity to x = 90 and y = -180 the whole pictures turns dark. Why?
@harleywaters1563 жыл бұрын
Make sure you've disabled receive shadow, and change material shader to unlit/texture
@seanholmes74823 жыл бұрын
@@harleywaters156 , do you have other videos on Unity? The object I work with keeps falling.
@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 Жыл бұрын
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..
@alexhomola69272 ай бұрын
@@EnchantedFailure im a bit late but yeah I had the same issue but then I realized
@daniel_druziki2 жыл бұрын
does this work for mobile game?
@IAmScarab3 жыл бұрын
Looks like a great scrolling effect but how would you make this scroll with the players movement instead off continuosly?
@Finlzz3 жыл бұрын
Dani has a good tutorial for what you want
@trungthanhbp4 жыл бұрын
Nice assets, can i ask where you get it ^^
@comp3interactive4 жыл бұрын
Sorry man. This was just a royalty free image I came across
@davidreddick52443 жыл бұрын
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.
@PeteThePangolin2 жыл бұрын
Any fix? I ran into this
@EvanPilb Жыл бұрын
@@PeteThePangolin Fix: don't use webgl, don't use webgl on mobile
@vineq93672 жыл бұрын
My background doesn´t move (3d game) Help.
@manolisroutsis5227 Жыл бұрын
can youi send me the image which you used to tutorial i need the exact same one
@ErcumentCozerx2 жыл бұрын
I did but my character is 2d but plane object is 3d so my character is falling down from the ground that I made
@kabhes90402 жыл бұрын
Okay but if the character doesn't move the background doesn't ether.
@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-lg2bs2 жыл бұрын
Doesn't work for me.
@ippulnugroho Жыл бұрын
how about vertical?
@inkkles10 ай бұрын
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