Hi
I’m making an infinite background that goes down along the Y-axis.
Basically the background sprite transforms back to its initial position when it has reached the maxYposition that I’ve setup.
However my sprite background objects moves always way past the maxYPosition I’ve set up.
Example: maxYPos = -5.6 but it snaps back to initial position when something like -6.6 is reached.
If I test my code in a new scene it works flawless.
What could be the reason my Update() responds so slow?
My C# code:
using UnityEngine;
using System.Collections;
public class MoveBuilding : MonoBehaviour {
public float backgroundMoveSpeed = 10f;
public double maxYPos;
private Vector3 startPos;
// Use this for initialization
void Start () {
startPos = transform.position;
}
// Update is called once per frame
void Update () {
//Moves object down
if(transform.position.y <= maxYPos){
transform.position = startPos;
}
transform.Translate(0, Time.deltaTime * -backgroundMoveSpeed, 0);
}
}