- Home /
How do I get something that goes off camera to appear on the opposite side ?
First post here, I've found plenty of help on the site otherwise but I can't seem to find an answer for my question. Basically, I just want my background to slide off camera but appear on the other side. Just vertically scrolling. I have the background sliding up now but I can't figure out where to go from here..(I'm pretty novice coding wise btw). Any help would be great.
I can only think of something else I read which was make a cylinder and make it turn with a texture on it. I can post my code if need be but it's just the basic Time.deltaTime code with a variable.
Answer by robertbu · Feb 14, 2014 at 06:27 PM
This is often done by Material.SetTextureOffset(), which rotates the texture, not the whole game object. There is example code in the reference. Plus if you Google "Unity SetTextureOffset" you will find other examples.
I found your rotating cylinder idea creative and potentially workable...especially unlit and especially for an Orthographic camera.
Thanks for the quick response. After doing a quick search on the settextureoffset, if I'm understanding correctly the material scrolls on the object(via plane/cube etc) ins$$anonymous$$d of the entire thing moving right ??
Correct. A Quad is a good choice for a background. Note from your title, I though you wanted something more like asteroids where an object disappears on one side and then reappears on the other, but your 'cylinder' idea pointed me towards SetTextureOffset(). Note the 'Wrap $$anonymous$$ode' for the texture you use must be set to 'Repeat' for SetTextureOffset() to work.
I got it working pretty well. The SetTextureOffset is perfect. I have it on a plane right now, how come a quad would be a better choice ?? Also how would I go about changing it to a vertical scroll rather than horizontal. I played with the code a bit but kept getting compile errors.
Also with the cylinder wouldn't it look odd ? because part of the texture would be slightly further back from the camera ?? Like the top and bottom would be further back than the middle.
When a Quad has (0,0,0) rotation it's visible back is to the camera when the camera has (0,0,0) rotation. So it is a nice way to display a texture for a standard/default setup. Plus a Quad only has 2 triangles.
You need to change the Vector2 passed for vertical:
renderer.material.SetTextureOffset("_$$anonymous$$ainTex", new Vector2(0, offset));
As for the cylinder, how much distortion would be based on how much of the cylinder was visible on the screen. If the cylinder was significantly bigger than the screen, then the distortion would be $$anonymous$$imal and would look okay. SetTextureOffset() is a much better solution (I$$anonymous$$HO), but I liked the way you came up with a solution using the tools you knew.
Your answer
Follow this Question
Related Questions
Resolution Independent Scrolling Background 0 Answers
How to script a repeating environment texture 3 Answers
Randomly Transition Camera Background Color? 2 Answers
Most efficient way to darken the screen? 3 Answers