I have an image that’s acting as a background with this script attached to it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BG_Mover : MonoBehaviour {
Transform player;
private Vector3 offset;
void Start() {
player = GameObject.Find("Done_Player").transform;
offset = transform.position - player.transform.position;
}
void LateUpdate() {
transform.position = new Vector3(player.position.x, transform.position.y, transform.position.z) + offset;
}
}
What this script is supposed to do is make the image follow the player’s z coordinate, but not the x and y coordinate. Although, I made a Vector3
that is the offset of the player’s z and the image’s z. Basically, I want the difference between the player’s z and the image’s z (80) to stay the same.
Although, when I run it, the image just keeps on adding up and it flies out of the view of the camera.
What is causing the problem, and how can I fix this?