Transform position check in update is slow

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);
	}
}

Chache your transform component. Read this guide for detailed informations. I am used to make my own derived class of MonoBehaviour which overrides these shortcut getters, and caches those references when i do the first lookup with them.

The answer of Robert Acksel solved it, along with teaching me a better way to program the transforms. Thank you very very much!!

Solution in C#, for future reference:

using UnityEngine;
using System.Collections;

public class MoveBuilding : MonoBehaviour {

	public float backgroundMoveSpeed = 10f;
	public double maxYPos;
	private Vector3 startPos;
	private Transform transformCache;

	// Use this for initialization
	void Start () {
		startPos = transform.position;
	}

	void Awake () {
		transformCache = transform;
	}
	
	// Update is called once per frame
	void Update () {
		//Moves object down
		if(transformCache.position.y <= maxYPos){
			transformCache.position = startPos;
		}
		transformCache.Translate(0, Time.deltaTime * -backgroundMoveSpeed, 0);
	}
}