Ok so before I even attempted to ask this question I thought about this little piece of code for about a week. I wasn’t even sure what to ask. That’s how cryptic it is to me.
parallaxScales = new float[backgrounds.Length];
for (int i = 0; i < backgrounds.Length; i++) {
parallaxScales <em>= backgrounds_.position.z*-1; and apply z position * -1_</em>
* }*
Anyways I guess I was just wondering if someone could explain what is going on because i’ve never really seen anything like it before. It seems like a new a new float, an array, is being assigned to this variable. but then it shows this same variable(a float) having a position assigned to it. (I hope that made sense, still a beginner) I was wondering if someone could break it down a little more than the person who made the tutorial did.
Here is the entire script and link for the tutorial 3. How to make a 2D Platformer - Parallax Scrolling - Unity Tutorial - YouTube
using UnityEngine;
using System.Collections;
public class Parallaxing : MonoBehaviour {
* public Transform[] backgrounds; *
* private float[] parallaxScales; *
* public float smoothing = 1f; *
* private Transform cam; *
* private Vector3 previousCamPos; *
* void Awake () {*
* cam = Camera.main.transform;*
* }*
* void Start () {*
* previousCamPos = cam.position;*
* parallaxScales = new float[backgrounds.Length];*
* for (int i = 0; i < backgrounds.Length; i++) {*
parallaxScales = backgrounds_.position.z*-1;
* }*_
* }*
* void Update () {*
* for (int i = 0; i < backgrounds.Length; i++) {*
_ float parallax = (previousCamPos.x - cam.position.x) * parallaxScales*;*_
_ float backgroundTargetPosX = backgrounds*.position.x + parallax;*_
Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds_.position.y, backgrounds*.position.z);*_
backgrounds.position = Vector3.Lerp (backgrounds_.position, backgroundTargetPos, smoothing * Time.deltaTime);
* }*_
* previousCamPos = cam.position;*
* }*
}