- Home /
CS1519 C# error `void'?
Help me where did I go wrong?
using UnityEngine; using System.Collections;
public class Parallaxing : MonoBehaviour { public Transform [] backgrounds; // Array (list) of all the back and foregrounds to be parallaxed private float [] parallaxScales; // The proportion of the camera's movement to move the backgrounds by public float [] smoothing = 1f; // How smooth the parallax is going to be. Make sure to set this above zero
private Transform cam; // Refrence to the main camera's transform
private Vector3 PreviousCamPos // the position of the camera in its previous frame
// Is called before Start (). Great for references
void Awake () {
// set up camera the reference
cam = Camera.main.transform;
}
// Use this for initialization
void Start () {
// The previous frame had the current frame's camera precision
PreviousCamPos = cam.position;
// assigning corresponding parralax scales
parallaxScales = new float[backgrounds.Length];
for (int i = 0; i < backgrounds.Length; i++) {
parallaxScales[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++) {
// The parallax is the opposite of the camera movement because the previous frame multiplied by the scaale
float parallax = (PreviousCamPos.x - Cam.position.x) * parallaxScales [i];
// set a target x position which is the current position + the parallax
float backgroundTargetPosX = background [i].position.x = parallax;
// create a target position which is the background current position with it's target x position
Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds [i].position.y, backgrounds [i].position.z);
// fade between current position and the target position using what is called lerp
backgrounds [i].position = Vector3.Lerp (backgrounds [i].position, backgroundTargetPos, smoothing * Time.deltaTime);
}
// set the previous Pos to the camera's Pos at the end of the frame
PreviousCamPos = cam.position;
}
}
Can you format the code correctly please.
Can you also copy and paste the entire error as it appears in the console, do not paraphrase it or type it by hand.
Answer by tanoshimi · Jul 05, 2014 at 08:43 AM
Error messages are there to help you. If you'd read the whole thing you'd have seen that it gives you the line number which pinpoints exactly where you've gone wrong....
private Vector3 PreviousCamPos
Is missing a semicolon at the end of the line.
Your answer

Follow this Question
Related Questions
No Overload for method 'Instantiate' takes '7' arguments? 4 Answers
How to add collision detection between two game objects? 2 Answers
OnMouseEnter, change color. 1 Answer
Global name space error c# 0 Answers
SetActive() not working 2 Answers