TheWebExpert wants to know: How do I make a parallax scrolling background?

I’ve seen several tutorials on the web, yet have been unsuccessful in getting them to work. What I want is a foreground image, with two moving background images behind it. The sample I found at http://www.raywenderlich.com/78675/unity-new-gui-part-1.html is a great example of what I’m looking for.
However, when I modify the code so that my foreground image stays still and the background images keep moving, the “mouse” character they’ve created moves forward as well. I want an animated character that DOESN’T move (or, one that I can move without affecting the movement of the background images).
I’ve tried about a dozen tutorials so far, and even following the directions to the letter (or as closely as possible), my backgrounds don’t move. (As far as “close as possible,” I’m talking about their version of Unity being different from mine, for instance with the Legacy Shaders.
What I’d like is a sample I can just “plug in,” as it were, and/or a tutorial which is known to work. Can anybody help?

I want to learn this… but following a tutorial that doesn’t work teaches me nothing. With a piece of working code, I can study it & figure out the how & why. Thanks!

If you can at least point me to a WORKING tutorial, I’d be very grateful.

I do not know of any tutorial but a simple way is just make two GameObjects in your scene. Name one Background and the other Foreground. Put your background image(s) under (children of) the Background GO. Put your foreground images under the Foreground GO. Now just move the Background GO and Foreground GO as you want.

This might not be exactly what you are looking for, but you might learn something from it…

Thank you very much for your reply. The answer was indeed helpful. I played with the code a bit and came up with this modification:

void Update ()
{
//The parallax is the opposite of the camera movement,
//because the previous frame because the previous
//frame multiplied by the scale
float parallax1 = (previousCamPos.x – cam.position.x) * parallaxScales[0];
float parallax2 = (previousCamPos.x – cam.position.x) * parallaxScales[1];
//Set a target x position which is the current position
//plus the parallax
float imageTargetPosX1 = images[0].position.x + parallax1;
float imageTargetPosX2 = images[1].position.x + parallax2;
//Create a target position which is the images’s
//current position with its target x position
Vector3 imageTargetPos1 = new Vector3 (imageTargetPosX1 – 2, images[0].position.y, images[0].position.z);
//Fade between current position & target position using lerp
images[0].position = Vector3.Lerp (images[0].position, imageTargetPos1, smoothing * Time.deltaTime);
Vector3 imageTargetPos2 = new Vector3 (imageTargetPosX2 – 3, images[1].position.y, images[1].position.z);
//Fade between current position & target position using lerp
images[1].position = Vector3.Lerp (images[1].position, imageTargetPos2, smoothing * Time.deltaTime);
//Set previous camera position to the camera’s position at the end of the frame
previousCamPos = cam.position;
}

What I have now is the still foreground (great) and two separate moving backgrounds (even better)! I’ll add variables later so that I can control the speed without having to edit the code, but that’s fine.
The main problem I have now is this: a). How do I know when image #1 has moved far enough left so that I now have to make a repeat copy of it x pixels to the right so that the animation stays seamless? b). How to I actually make that copy?
Both images are seamless (they’re also temporary, while I’m learning to do this). I know it can be done, but I just need that teensy eensy bit more help…

There’s a few very good parallax scrolling assets on the Asset Store. Ranging from free to still pretty cheap