Hello everyone.
I get Assets/Parallaxing.cs(43,31): error CS1525: Unexpected symbol 'vector3'
using UnityEngine;
using System.Collections;
public class Parallaxing : MonoBehaviour {
public Transform[] backgrounds; //Lista de el fondo - foreground por se parallaxed
private float[] parallaxCuanto; //La proporcio de cuanto quiero que se mueva la camara
public float suavizado = 1f; // Que tan suave tiene que ser el paralax (poner esto por encima de 0)
private Transform cam; // reference to the main cameras trasnform
private Vector3 ultposcam; //Esto va a guardar la ultima posicion de la camara (en el ultimo frame)
// Is called before start (). Bueno para referencias.
void Awake () {
// poner la referencia de la camara
cam = Camera.main.transform;
}
// Use this for initialization
void Start () {
// the previous frame had thbe current frame's camera position
ultposcam = cam.position;
//poniendole correspondientes parallaxScales
parallaxCuanto = new float[backgrounds.Length];
for (int i = 0; i < backgrounds.Length; i++) {
parallaxCuanto [i] = backgrounds [i].position.z * -1;
}
}
// Update is called once per frame
void Update () {
// for each background
for (int i = 0; i < backgrounds.Length; i++) {
// theparralax is the opposite of te camera movement becuase the previous frame multiplied by the scale
float parallax = (ultposcam.x - cam.position.x) * parallaxScales [i];
// set a target x position which is the current position plus the parallax
float backgroundTargetPosX = backgrounds [i].position.x + parallax
// create a target position which is the background's current positionwith it's target x position
Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds[i].position.y, backgrounds[i].position.z);
// fade between current position and te target position using lerp
backgrounds[i].position = Vector3.Lerp (backgrounds[i].position, backgroundTargetPos, suavizado * Time.deltatime);
}
// set the ultposcam to the camera's position at the end of the frame
ultposcam = cam.position;
}
}
↧