Question by
freezestime · Sep 30, 2016 at 01:16 AM ·
c#camera2d2d game2d-platformer
CS1216 error
So I'm new right, and I need help.
I'm following Brackey's 2D Platformer tutorials and for some reason, this error happens.
"Assets/Parallaxing.cs(24,60): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable"
"Cannot modify the return value of 'UnityEngine.Transform.position' because it is not a variable"
And he doesn't get it, and nobody else seems to get it so I'm stuck here (Btw I'm using the actual script from his website so idk)
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;
}
// Use this for initialization
void Start () {
previousCamPos = cam.position;
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 (int i = 0; i < backgrounds.Length; i++) {
float parallax = (previousCamPos.x - cam.position.x) * parallaxScales[i];
float backgroundTargetPosX = backgrounds[i].position.x + parallax;
Vector3 backgroundTargetPos = new Vector3 (backgroundTargetPosX, backgrounds[i].position.y, backgrounds[i].position.z);
backgrounds[i].position = Vector3.Lerp (backgrounds[i].position, backgroundTargetPos, smoothing * Time.deltaTime);
}
previousCamPos = cam.position;
}
}
Comment