So Im trying to make an parallax backround with one background and then one foreground. I followed brackeys tutorial and have no idea of what I just wrote, Im pretty new and I understand certain parts, but not the overall connection between the codes. However, the background moves way too fast and when I change the smoothing value nothing noticable really happends so please help me :S
EDIT: the code’s C#
using UnityEngine;
using System.Collections;
public class Parallaxing : MonoBehaviour {
public Transform[] backgrounds; // List of all the back and foreground to be parallaxed
private float[] parallaxScales; // The proportion of the camera's movement to move the backround by
public float smoothing = 1f; // How smooth the parallax is going to be. Make sure to set this above 0
private Transform cam; // Reference to the main cameras transform
private Vector3 previousCamPos; // the position of the camera in the previous frame
//Awake = Called before start
void Awake (){
//set up the camerarefrence
cam = Camera.main.transform;
}
// Use this for initialization
void Start () {
//the previous frame had the current frames camera position
previousCamPos = cam.position;
// assingning corespongding parallaxScales
parallaxScales = new float[backgrounds.Length];
for (int i = 0; i < backgrounds.Length; i++){
parallaxScales <em>= backgrounds_.position.z*-1;_</em>
* }*
* }*
* // Update is called once per frame*
* void Update () {*
* // for each background*
* for (int i = 0; i < backgrounds.Length; i++){*
* // the parallax is the opposite of the cameramovement because the previous frame multiplied by the scale*
_ float parallax = (previousCamPos.x = cam.position.x) * parallaxScales*;*_
* // set a target x position which is the current position plus the parallax*
_ float backgroundTargetPosX = backgrounds*.position.x + parallax;*_
* // creaye a target position which is the background’s current position with it’s target x position*
Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds_.position.y,backgrounds*.position.z);*_
* // fade between current position and the target position using lerp*
backgrounds_.position = Vector3.Lerp (backgrounds*.position, backgroundTargetPos, smoothing = Time.deltaTime);
}*_
* // set the previousCamPos to the cameras position at the end of the frame*
* previousCamPos = cam.position;*
* }*
}