Need help with Paralaxing code

Updated on March 2, 2018 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on March 2, 2018

Hi, I desperately need some help with paralaxing code from the 2D platformer tutorial video. I suspect that things have changed in Unity since that video was released and I cannot get it working. I’ve searched online and in the forum for answers, but no luck. Here is my code and the errors:


    <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;"> Update is called once per<span style="font-style: italic; color: #888888;"> frame<br />    void Update () <span style="color: #333333;">{<br />
            <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;"> for each<span style="font-style: italic; color: #888888;"> background<br />            <span style="color: #c44c57;">fot<span style="color: #333333;"> (int<span style="color: #333333;"> i <span style="color: #333333;">= 0; 1 < backgrounds.Length;<span style="color: #333333;"> i<span style="color: #333333;">++) <span style="color: #333333;">{<br />                <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;"> the <span style="font-style: italic; color: #888888;">parallax<span style="font-style: italic; color: #888888;"> is the <span style="font-style: italic; color: #888888;">opposite<span style="font-style: italic; color: #888888;"> of the camera movement <span style="font-style: italic; color: #888888;">because<span style="font-style: italic; color: #888888;"> the <span style="font-style: italic; color: #888888;">previous<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">frame<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">multiplied<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">by<span style="font-style: italic; color: #888888;"> the<span style="font-style: italic; color: #888888;"> scale<br />                float parallax = (previousCamPos.x - CamPosition.x) * <span style="color: #333333;">parallaxScales<span style="color: #333333;">[i];
                <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;">set<span style="font-style: italic; color: #888888;"> a target x position which is the current position <span style="font-style: italic; color: #888888;">plus<span style="font-style: italic; color: #888888;"> the<span style="font-style: italic; color: #888888;"> paralax<br />                float backgroundTargetPosX = backgrounds[i].position.x + parallax;
                <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">create<span style="font-style: italic; color: #888888;"> a target position which is the <span style="font-style: italic; color: #888888;">background<span style="font-style: italic; color: #888888;">'s current position <span style="font-style: italic; color: #888888;">with<span style="font-style: italic; color: #888888;"> it's target x<span style="font-style: italic; color: #888888;"> position<br />                Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds[i].position.<span style="color: #f57d00;">7<span style="color: #333333;">, backgrounds[i].position.<span style="color: #333333;">z<span style="color: #333333;">);
                <span style="font-style: italic; color: #888888;">//<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">fade<span style="font-style: italic; color: #888888;"> <span style="font-style: italic; color: #888888;">between<span style="font-style: italic; color: #888888;"> current position and the target position <span style="font-style: italic; color: #888888;">using<span style="font-style: italic; color: #888888;"> lerp<br />                backgrounds[i].position = Vector3.Lerp (backgrounds[i].position, backgroundTargetPos, smoothing * Time.deltaTime);
            }

Errors are:

Assets/Paralaxing.cs(39,12): error CS1525: Unexpected symbol `i’, expecting `.’

Assets/Paralaxing.cs(39,46): error CS1525: Unexpected symbol `)’, expecting `;’ or `}’

Assets/Paralaxing.cs(47,91): error CS1525: Unexpected symbol `0,7′

Thanks!

  • Liked by
Reply
0 on March 2, 2018

The code won’t come out properly even when I use code tags, sorry.

  • Liked by
Reply
Cancel
0 on March 2, 2018

Just follow the errors. All of them are in the Paralaxing script.

The first 2 are both at line 39, I’m guessing that’s the beginning or end of a for loop based on the ‘i’ character and that it’s looking for a terminating character like ‘;’ or ‘}’. Probably forgot to initialize ‘i’, and the other one is just a compound error because of it.

The 3rd on is at line 47, because it’s not expecting anything, I think that’s just a missing ‘;’

 

Without seeing the code I can’t tell you exactly what the error is, but hopefully this is enough to help you find and fix it.

  • Liked by
Reply
Cancel